Error reference
Every rejection carries a code, a source span, and a help: line with a rewrite. This page explains each code. The list is generated from the validator's code table, so it always matches the compiler; a test fails if a code is missing here.
error[CS1221]: `toPrecision` on a number is not supported yet
--> format.ts:2:31
help: build the string form manually, or use `.toString()` / template interpolation| Code | Meaning |
|---|---|
| CS0001 | TypeScript error |
| CS1000 | Not in the subset |
| CS1201 | any |
| CS1202 | enum |
| CS1203 | == and != |
| CS1204 | Non-null assertion x! |
| CS1205 | as any / as unknown |
| CS1206 | delete |
| CS1207 | Index signatures |
| CS1208 | Decorators |
| CS1209 | namespace / module blocks |
| CS1210 | with |
| CS1211 | eval / new Function |
| CS1212 | var |
| CS1213 | Regular expressions |
| CS1214 | JSON.parse form |
| CS1215 | Date |
| CS1216 | UTF-16 dependent string operation |
| CS1217 | Optional or default parameter form |
| CS1218 | Declaration without initializer |
| CS1220 | Unsupported static method |
| CS1221 | Unsupported number method |
| CS1222 | Unsupported Map / Set operation |
| CS1223 | Unsupported string method |
| CS1224 | Unsupported array method |
| CS1225 | Method call on an unsupported receiver |
| CS1226 | Unsupported module form |
| CS1227 | Duplicate class name |
| CS1228 | Module variable read before its declaration runs |
| CS1229 | process.argv form |
| CS1230 | Recursive type |
| CS1231 | Async timer callback |
| CS1232 | Async function used as a value |
| CS1233 | Type with no representation |
| CS1234 | Opaque handle used as a value |
| CS1235 | Property added at run time |
| CS1236 | Too many layouts at one site |
| CS1237 | Method implementations disagree on machine types |
| CS1238 | Value that cannot be printed |
| CS1239 | Operation on an un-narrowed union |
| CS1240 | Representation mismatch |
| CS1241 | Stale narrowing of a captured variable |
| CS1242 | Generic instantiated with a container or function |
| CS1243 | Type-level computation |
| CS1244 | Constructor type |
| CS1246 | Built-in function used as a value |
| CS1247 | Value that cannot be thrown |
| CS1248 | Unsupported use of a caught value |
| CS1249 | Network API call in an unsupported form |
| CS1250 | Variable read by a function in its own initializer |
| CS9000 | Internal compiler error |
CS0001: TypeScript error
The program does not typecheck under the strict options ChadScript imposes (strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes, noImplicitOverride, noPropertyAccessFromIndexSignature). TypeScript's checker decides every type, so a program with any type error is not compiled. Importing a name that a built-in module (node:fs, node:path) does not provide in the subset also lands here, because stdlib/globals.d.ts only declares what is supported.
Rewrite: Fix the type error tsc reports. The message after the code is tsc's own.
Rejection tests: const-reassign.ts, fs-promises-unsupported-export.ts, main.ts and 2 more
CS1000: Not in the subset
The general rejection. The compiler accepts a construct only when it has a rule for it, backed by a test that checks the result against Node; anything else stops here. The message names the construct (for example GetAccessor, a method in an object literal, top-level await, a nested function declaration, an optional chain longer than one ?.). It also covers the built-in classes: a class that extends Error or another built-in class, new of a built-in class the subset does not construct, and instanceof against anything but your own classes and the four error classes. On errors, .stack and assignments to an error's fields (e.message = ...) are rejected. Spreading an array into the arguments of a library function (Math.max(...xs)) is rejected. new Promise needs its executor written inline with typed parameters ((resolve: (value: T) => void, reject: (reason: Error) => void): void => { ... }), new Set(...) takes an array, and new Map(...) takes only an array literal of [key, value] pairs.
Rewrite: Follow the help: line, which is specific to the construct. The subset reference lists every admitted syntax kind.
Status: planned to be admitted in a later phase.
Rejection tests: arguments-object.ts, assign-as-value.ts, bigint-literal.ts and 26 more
CS1201: any
any switches off the type checker, and the compiler needs a static type for every value to choose its representation.
Rewrite: Give the value a concrete type, or a union of the types it can hold.
Rejection tests: any-annotation.ts
CS1202: enum
TypeScript enums generate a runtime object with reverse mappings; they are not in the subset.
Rewrite: Use a union of string literals (type Color = "red" | "green") or an as const object.
Rejection tests: enum-decl.ts
CS1203: == and !=
Loose equality applies JavaScript's coercion table; the subset only has strict equality.
Rewrite: Use === / !==. To test for both null and undefined, write both comparisons.
Rejection tests: loose-eq.ts, loose-neq.ts
CS1204: Non-null assertion x!
Node erases x! without a check. It is admitted only where it changes no representation (a no-op on a Value word); elsewhere it would need a representation change that Node never performs.
Rewrite: Narrow explicitly: if (x !== undefined) { ... }, or use x ?? fallback.
Rejection tests: non-null.ts
CS1205: as any / as unknown
Casting through any or unknown escapes the type system.
Rewrite: Narrow the value with typeof, instanceof or a discriminant instead.
Rejection tests: as-any.ts
CS1206: delete
Objects have a fixed shape after allocation; removing a property would change it at run time.
Rewrite: Model optional presence with an optional field (x?: T) or use a Map.
Rejection tests: delete-op.ts
CS1207: Index signatures
{ [k: string]: T } describes an object whose keys are only known at run time, which the static shape model cannot lay out.
Rewrite: Use Map<string, T> for dynamic keys.
Rejection tests: index-sig.ts
CS1208: Decorators
Decorators run arbitrary code against classes at definition time.
Rewrite: Call the wrapping function explicitly.
CS1209: namespace / module blocks
TypeScript namespaces create runtime objects; the subset uses ES modules only.
Rewrite: Split the code into files and use import / export.
Rejection tests: namespace-decl.ts
CS1210: with
with makes name resolution dynamic.
Rewrite: Access the properties explicitly.
CS1211: eval / new Function
There is no interpreter in a compiled binary, so code cannot be created at run time.
Rewrite: Write the function directly. Programs that need eval should run on Node.
Rejection tests: eval-call.ts
CS1212: var
var hoists to function scope; the subset uses block-scoped bindings only.
Rewrite: Use let or const.
Rejection tests: var-keyword.ts
CS1213: Regular expressions
Regex literals and RegExp are not in the subset yet.
Rewrite: Use string methods (includes, indexOf, split, replace with a string pattern).
Status: planned to be admitted in a later phase.
Rejection tests: regex-literal.ts
CS1214: JSON.parse form
JSON.parse must have a declared target type, because the compiler checks the parsed document against it (and throws on a mismatch). The reviver argument, and targets that mix object types with other kinds in one union, are not supported.
Rewrite: Annotate the target: const cfg: Config = JSON.parse(text);. See JSON.
Rejection tests: json-parse-object-union.ts, json-parse-reviver.ts, json-parse-unannotated.ts and 1 more
CS1215: Date
Only Date.now() is in the subset; Date instances need calendar arithmetic that has not landed.
Rewrite: Use Date.now() (epoch milliseconds).
Status: planned to be admitted in a later phase.
Rejection tests: date-new.ts, date-parse.ts
CS1216: UTF-16 dependent string operation
Strings are ASCII for now: a non-ASCII string literal (or escape) is rejected, and non-ASCII text arriving at run time stops the program. String.fromCharCode and fromCodePoint stay gated because they could build a non-ASCII string. Full Unicode is a later phase.
Rewrite: Use charAt(i) or at(i), compare strings with ===, and keep literals ASCII for now.
Status: planned to be admitted in a later phase.
Rejection tests: string-fromcharcode.ts, string-non-ascii-escape.ts, string-non-ascii-literal.ts
CS1217: Optional or default parameter form
Optional (x?) and default (x = v) parameters are supported, except: a destructured parameter with a default, a default that reads a later parameter, a parameter whose type holds only null/undefined, and a function with optional or default parameters used as a function type that lists fewer parameters (a call through that type would not pass them).
Rewrite: Destructure in the body, reorder the parameters, or list the extra parameters in the function type ((x: number, y?: number) => R), or pass a wrapper (x) => f(x).
Rejection tests: param-default-destructured.ts, param-default-fnref-fewer-params.ts, param-default-later-param.ts and 3 more
CS1218: Declaration without initializer
let x: T; without a value is not supported yet.
Rewrite: Initialize at the declaration: let x: T = initial;.
Status: planned to be admitted in a later phase.
Rejection tests: uninit-var.ts
CS1220: Unsupported static method
A static on a built-in namespace (Array.*, Number.*, Object.*, Promise.*, ...) that is not on the allowlist. The message lists the supported ones.
Rewrite: Use a supported static or write the loop. The subset reference lists them.
Status: planned to be admitted in a later phase.
Rejection tests: array-from.ts, global-encode-uri.ts, math-transcendental.ts and 4 more
CS1221: Unsupported number method
toPrecision and toExponential are not supported yet (toFixed is).
Rewrite: Use n.toFixed(d), String(n) or template interpolation.
Status: planned to be admitted in a later phase.
Rejection tests: number-toexponential.ts, number-toprecision.ts
CS1222: Unsupported Map / Set operation
A Map/Set method outside the allowlist (for example entries), iterating a Map directly with for...of, or keeping an iterator from keys() / values() as a value.
Rewrite: Iterate keys and read values: for (const k of m.keys()) { const v = m.get(k); }, or snapshot with [...m.keys()].
Status: planned to be admitted in a later phase.
Rejection tests: collection-iterator-held.ts, for-of-map.ts, log-map-iterator.ts
CS1223: Unsupported string method
A String.prototype method outside the allowlist. The message lists the supported ones.
Rewrite: Use a supported method; the subset reference lists them.
Status: planned to be admitted in a later phase.
Rejection tests: string-normalize.ts
CS1224: Unsupported array method
An Array.prototype method outside the allowlist. The message lists the supported ones.
Rewrite: Use a supported method; the subset reference lists them.
Status: planned to be admitted in a later phase.
Rejection tests: array-fill.ts
CS1225: Method call on an unsupported receiver
Calling a method on a value whose type is neither a class instance nor an interface or object type.
Rewrite: Call methods on class instances, or on objects typed by an interface or object type.
CS1226: Unsupported module form
An import or export the module system does not support: CommonJS (require, export =), dynamic import(), a package that ships only JavaScript and declarations, a namespace import used as a value, export * as ns, or an anonymous default class.
Rewrite: Use static ESM imports and named or default exports. A package must ship its TypeScript source. See Modules.
Rejection tests: main.ts, main.ts, module-dynamic-import.ts and 6 more
CS1227: Duplicate class name
Reserved for two classes in one program that share a name.
Rewrite: Rename one of them.
Status: reserved. No validator rule emits this code today.
CS1228: Module variable read before its declaration runs
A function reads a module-level variable, and code that calls the function runs before the declaration. Node throws ReferenceError there (the temporal dead zone).
Rewrite: Move the declaration above the code that runs first.
Rejection tests: class-tdz.ts, module-var-tdz-via-callback.ts, module-var-tdz-via-method.ts and 2 more
CS1229: process.argv form
argv[0] and argv[1] are the node binary and the script path, which have no equivalent in a compiled binary. Only process.argv.slice(2) means the same thing in both.
Rewrite: Write const args = process.argv.slice(2); and index into args.
Rejection tests: argv-whole-array.ts
CS1230: Recursive type
Reserved for types that refer to themselves. Recursive types such as trees and linked lists compile today.
Rewrite: Nothing to rewrite.
Status: reserved. No validator rule emits this code today.
CS1231: Async timer callback
TypeScript accepts setTimeout(async () => ...), but a rejection inside it would have nothing to await it.
Rewrite: Make the callback synchronous, or have it call an async function whose promise you handle.
Rejection tests: timer-async-callback.ts
CS1232: Async function used as a value
An async function declaration referenced without calling it.
Rewrite: Wrap it: (x) => f(x).
Rejection tests: fn-ref-async.ts, main.ts, main.ts
CS1233: Type with no representation
A value whose type the value domain cannot represent: a tuple with different element types, an empty never[] literal, a union no runtime tag can tell apart (two array types), a union used as a Map/Set key, or a Promise<null> (a promise of only null).
Rewrite: Follow the help: line: usually an object with named fields, or an explicit element type.
Status: planned to be admitted in a later phase.
Rejection tests: empty-array-no-type.ts, never-narrowed-read.ts, promise-of-null.ts and 4 more
CS1234: Opaque handle used as a value
A runtime handle (a timer id, a promise) used as anything but a stored or passed value.
Rewrite: Only store it, pass it, or give it back to the API that made it (clearTimeout(id)).
Rejection tests: net-brand-member.ts, net-print-buffer.ts, net-print-server.ts and 3 more
CS1235: Property added at run time
A write that can add a property to an object created without it. Objects keep the shape they were allocated with.
Rewrite: Create the object with the property (initialized to undefined if needed).
Rejection tests: json-parse-optional-write.ts, property-add.ts
CS1236: Too many layouts at one site
A spread or Object.values that can see objects of too many runtime layouts, or an object made by JSON.parse whose key order is only known at run time.
Rewrite: Copy the fields you need explicitly: { a: src.a, b: src.b }.
Rejection tests: json-parse-spread.ts, object-values-mixed-layouts.ts, spread-layout-limit.ts
CS1237: Method implementations disagree on machine types
A call through an interface where the implementations reachable at run time take or return different machine representations.
Rewrite: Give the implementations the same parameter and return types.
Rejection tests: method-representation-mismatch.ts, param-default-override-arity.ts, param-optional-impl-required.ts
CS1238: Value that cannot be printed
console.log, JSON.stringify or a format directive given a value that can hold something the runtime cannot render the way Node does (for example a promise). It also covers turning a value into a string (String(x), a template literal, + with a string, join) when the value can be a function (Node prints its source text), an object with a valueOf method, or an object whose own toString() its declared type does not declare.
Rewrite: Print the fields you need, or await the promise first. To convert an object to text, give its declared class or interface a toString(): string method, or build the text from its fields (${p.name}).
Rejection tests: format-d-tostring.ts, format-dynamic-function.ts, format-o-function.ts and 9 more
CS1239: Operation on an un-narrowed union
An operation such as x + 1 or x.length on a union of different kinds. Printing, String(), templates, ===, typeof, ?? and truthiness work on any union; everything else needs one kind.
Rewrite: Narrow first: if (typeof x === "number") { x + 1 }.
Rejection tests: union-for-of.ts, union-member-access.ts
CS1240: Representation mismatch
A flow whose nested elements differ in representation, for example passing a number[] where a (number | string)[] is expected. Both would alias one array, and writes through the wider type would break the narrower one.
Rewrite: Copy into a new array of the wider type ([...xs] with an annotation), or use one element type throughout.
Rejection tests: array-callback-optional-param.ts, array-covariance-representation.ts, generic-array-alias.ts and 5 more
CS1241: Stale narrowing of a captured variable
A variable that a closure reassigns is read with a narrowed type after a call. The call may have run the closure, so tsc's narrowing can be stale.
Rewrite: Copy the value into a const before the call and use the copy.
Rejection tests: stale-narrowing.ts
CS1242: Generic instantiated with a container or function
Generics are compiled once with each type parameter as one self-describing word. An array, map or function type argument does not fit in that word.
Rewrite: Wrap it in an object ({ items: xs }), or write a non-generic function for that type.
Status: planned to be admitted in a later phase.
Rejection tests: generic-container-type-arg.ts
CS1243: Type-level computation
Conditional, mapped, indexed-access and keyof types are not supported.
Rewrite: Write the resulting type out as an interface or a union of literals.
Rejection tests: generic-conditional-type.ts, generic-keyof.ts
CS1244: Constructor type
new () => T: generic code cannot construct its type parameter.
Rewrite: Pass a factory function instead: make: () => T.
Rejection tests: generic-constructor-type.ts
CS1246: Built-in function used as a value
A built-in such as String, Math.floor or console.log passed as a value.
Rewrite: Wrap it in an arrow function: xs.map((x) => String(x)).
Rejection tests: builtin-member-as-value.ts, builtin-value-unsupported.ts
CS1247: Value that cannot be thrown
throw of something other than a string, one of the built-in errors (Error, TypeError, RangeError, SyntaxError) or a caught value: a number, an object, an instance of your own class, or a value that may be undefined.
Rewrite: Throw an error that describes it: throw new Error(String(x)). Keep extra data in a variable of its own, or return a result object instead of throwing.
Rejection tests: throw-class-instance.ts, throw-number.ts, throw-object.ts and 1 more
CS1248: Unsupported use of a caught value
&&, || or ?? with a caught value (catch (e)) as an operand, whose result's type (unknown or {}) has no representation in a compiled program; or a read of a caught value after a test proved it is something no thrown value is (a number after typeof e === "number", an array after Array.isArray(e)); or an assignment to a caught value. Only strings and errors can be thrown.
Rewrite: Test the value first (e instanceof Error, typeof e === "string"), or convert it: String(e) || "default".
Rejection tests: caught-value-assign.ts, caught-value-coalesce.ts, caught-value-narrowed-array.ts and 2 more
CS1249: Network API call in an unsupported form
A call into node:net (or another network API) that the compiler must see statically: connection options passed as a variable instead of an object literal, or a callback whose parameters cannot receive the values the runtime passes it (for example a parameter declared wider than the event's argument type).
Rewrite: Write the options inline (net.connect({ port, host }, onConnect)) and declare each callback parameter with the type the API declares for that event.
Rejection tests: net-connect-options-variable.ts, net-listener-param-type.ts
CS1250: Variable read by a function in its own initializer
const x = f(() => x): the function is created before x has a value. When f might call it right away, Node throws a ReferenceError, and a compiled program would read an empty variable instead. Network listeners and timers only run later, so passing the function to one of those is allowed.
Rewrite: Declare the variable first and assign the function afterwards, or pass the function to an API that calls it later.
Rejection tests: net-self-init-sync.ts
CS9000: Internal compiler error
A program passed the validator but a later stage could not compile it. This is always a compiler bug: the validator should have admitted the construct fully or rejected it with a code from this page.
Rewrite: Please open an issue with the smallest program that triggers it. Until it is fixed, rewrite the construct named in the message.
Next: CLI · Is ChadScript for you?.