Skip to content

JavaScript and TypeScript

Ali Al-Ramadan edited this page Nov 14, 2026 · 2 revisions

The rules of the method stereotypes, the free-function stereotypes, and the class stereotypes hold in JavaScript and TypeScript as in every language of Stereocode. This page gives the forms that the facts of these rules take in JavaScript and TypeScript, the built-in lists that Stereocode reads for JavaScript and TypeScript, and one labeled example of each stereotype. The page Python and JavaScript states in full how Stereocode reads data members, types, returned values, and calls in JavaScript and TypeScript.

Language Facts

  • srcML marks a TypeScript unit as JavaScript. Each rule for JavaScript therefore holds for TypeScript as well.
  • A method reaches its object through this. The # of a private name belongs to the name, as in this.#count.
  • A function without a return annotation returns void, boolean, the class that it creates, or any, by its returned values. An async function returns the value to which its promise resolves.
  • constructor gets constructor. JavaScript has no destructor and no copy constructor.
  • A function without a body, such as an abstract method or an overload signature, gets no stereotype.
  • The function declarations at the top level of a file and the static methods of a class get the free-function stereotypes with the option -f. TypeScript interfaces get their stereotypes with the option -i.

Built-in Lists

Stereocode reads four built-in lists for JavaScript and TypeScript. The list files of the options -p, -c, -s, and -q add entries to these lists under the section [JavaScript], as the README states. Each list below opens with a click.

Primitive types (18 entries)

A type of this list makes no method a collaborator and no return type of a factory.

any, BigInt, bigint, Boolean, boolean, Function, never, null, Number, number, object, String, string, Symbol, symbol, undefined, unknown, void

Ignored calls (9 entries)

The rules ignore a call of these names. A name without a qualifier, such as print, is ignored only as the whole name of a call.

alert, console.debug, console.error, console.info, console.log, console.trace, console.warn, process.exit, require

Specifiers and containers (32 entries)

Stereocode strips these entries from a written type before it reads the names of the type. A container counts by the types of its elements. Each entry is a regular expression, such as \.\.\. for ....

&, <, >, \?, \|, Array, AsyncGenerator, AsyncIterable, AsyncIterableIterator, AsyncIterator, Awaited, Generator, Iterable, IterableIterator, Iterator, keyof, Map, NonNullable, Partial, Promise, PromiseLike, Readonly, readonly, ReadonlyArray, ReadonlyMap, ReadonlySet, Record, Required, Set, typeof, WeakMap, WeakSet

Query methods (52 entries)

A call of these methods only reads the variable that the call is on.

at, charAt, charCodeAt, codePointAt, concat, endsWith, entries, every, filter, find, findIndex, findLast, findLastIndex, flat, flatMap, forEach, get, has, includes, indexOf, join, keys, lastIndexOf, localeCompare, map, match, matchAll, normalize, padEnd, padStart, reduce, reduceRight, repeat, replace, replaceAll, search, slice, some, split, startsWith, substring, toLowerCase, toReversed, toSorted, toSpliced, toString, toUpperCase, trim, trimEnd, trimStart, valueOf, values

Examples

Each example below is the declaration of an element from the stereotype cases of Stereocode, whose expected stereotypes are written by hand in @stereotype comments. Each link opens the case on the branch develop. The second column gives every stereotype of the element. A stereotype without an example has no case in JavaScript and TypeScript.

Methods

Stereotype Stereotypes of the element Declaration
get get getValue(): number | undefined
predicate predicate isFreezing(): boolean
property property read(count?: number): string
void-accessor void-accessor readCelsius(values: number[]): void
set set setRadius(radius: number): void
command command increment(): void
non-void-command property non-void-command withdrawAll()
factory factory stateless find(count: number): Matrix | undefined
collaborator set collaborator attach(printer: Printer): void
controller controller sendSecond(printer: Printer): void
wrapper wrapper announce(): void
incidental incidental greeting(name)
stateless stateless fail()
empty empty refresh() {}
constructor constructor constructor(printer: Printer, pages: number)
copy-constructor No case
destructor No case
unclassified unclassified show()

TABLE 1. Examples of the method stereotypes in JavaScript and TypeScript.

Free functions

Stereotype Stereotypes of the element Declaration
main No case
predicate predicate async function isReady(value)
property property export function square(value: number): number
global-command global-command export function raiseLevel()
command command function swap([left, right], pair)
factory property factory function makeWidget(style)
literal literal function copiedLevel()
wrapper wrapper function run(callback)
empty empty function noop(value) {}
unclassified unclassified function show(value)

TABLE 2. Examples of the free-function stereotypes in JavaScript and TypeScript, which the option -f assigns.

Types

Stereotype Stereotypes of the element Declaration
boundary entity boundary class Measure
commander minimal-entity commander class Counter
controller factory controller class WidgetFactory
data-class data-class class Pair
data-provider data-provider abstract class Base<T> implements Shape
empty empty interface Named
entity entity boundary class Measure
factory factory controller class WidgetFactory
minimal-entity minimal-entity commander class Counter
pure-controller pure-controller class Dispatcher
small-class data-provider small-class class Square<T> extends Base<T>

TABLE 3. Examples of the class stereotypes in JavaScript and TypeScript, where large-class, lazy-class, data-class, and small-class of a type of another kind take that kind in place of class, such as data-struct.

Clone this wiki locally