CHANGES.md lists intentional changes between the Strada (TypeScript) and Corsa (Go) compilers. # JavaScript support At a high level, JavaScript support in Corsa is intended to expose TypeScript features in a .js file, working exactly as they do in TypeScript with different syntax. This differs from Strada, which has many JavaScript features that do not exist in TypeScript at all, and quite a few differences in features that overlap. For example, Corsa uses the same rule for checking calls in both TypeScript and JavaScript; Strada lets you skip parameters with type `any`. And because Corsa uses the same rule for optional parameters, it fixes subtle Strada bugs with `"strict": true` in JavaScript. We primarily want to support people writing modern JavaScript, using things like ES modules, classes, destructuring, etc. To that end, we have trimmed a lot of unused or underused features. This makes the implementation much simpler and more like TypeScript. The biggest single removed area is support for Closure header files--most Closure-specific features, in fact. The tables below list removed Closure features along with the other removed features. Reminder: JavaScript support in TypeScript falls into three main categories: - JSDoc Tags - Expando declarations - CommonJS syntax An expando declaration is when you declare a property just by assigning to it, on a function, class or empty object literal: ```js function f() {} f.called = false; ``` One important use of expando declarations is no longer supported: constructor functions. ```js function C() { this.property = 1; } C.prototype.method = function() {} ``` Use classes instead: ```js class C { constructor() { this.property = 1; } method() {} } ``` ## Declaration Emit We've fundamentally rewritten core parts of the declaration emit *and* JavaScript parsing components. As a result, declaration (`.d.ts`) emit based on `.js` input files has substantially changed behavior. While it's still expected that supported tags (see below) are emitted with correct semantics in Corsa, it's a non-goal to exactly match Strada's output. This also has effects on how `.d.ts` is emitted in the presence of errors, which tends to be more common in `.js` and JSDoc scenarios. Declaration file generation isn't well-defined in the presence of errors (including those suppressed with `ts-ignore`/`ts-expect-error`), and you can expect Corsa and Strada to be quite different depending on the situation. However, if you see **_incorrect_** `.d.ts` output from a `.js` file, **please file an issue**. ## JSDoc Tags and Types | Name | Example | Substitute | Note | | -------------------------- | ------- | ----------- |----- | | UnknownType | `?` | `any` | | | NamepathType | `Module:file~id` | `import("file").id` | TS has never had semantics for this. | | `@class` |
|/** @class */function C() {
this.p = 1;}
| Use regular `class` declarations. | | `@enum` |class C {constructor() {this.p = 1;}}
|/\** @enum {number} */const E = { A: 1, B: 2 };
| Closure feature. | | `@author` |/** @typedef {number} E \*//** @type {Record} */ const E = { A: 1, B: 2 };
/** @author Finn */ | Keep the same. | `@treehouse` parses as a new tag in Corsa. |
| Identifier-named typedefs |`/** @typedef {T} */ typeName; | /** @typedef {T} typeName */ | Closure feature. |
| Closure function type syntax | /* @type {function(string): void} */ | /* @type {(s: string) => void} */ | |
| Automatic typeof insertion | |const o = { a: 1 };/\** @type {o} */var o2 = { a: 1 };
| | ## Expando declarations | Name | Example | Substitute | Note | | -------------------------- | ------- | ----------- |----- | | Constructor functions |const o = { a: 1 };/\** @type {typeof o} */var o2 = { a: 1 };
|function C() {this.p = 1;}C.prototype.m = function() { };
| Use regular `class` declarations. | | Fallback initialisers |class C {p = 1;m() { }}
f.x = f.x \|\| init; | if (!f.x) f.x = init; | |
| Nested, undeclared expandos | |var N = {};N.X.Y = {};
| All intermediate expandos have to be assigned. Closure feature. | | Identifier declarations |var N = {};N.X = {};N.X.Y = {};
|class C {
constructor() {
/\** @type {T} */
this.identifier;
}}
| Closure feature. | | `this` aliases |class C {
/\** @type {T} */
identifier;
constructor() { }}
|class C() {constructor() {var that = this;that.x = 12;}}
| | | `this` alias for `globalThis` |class C() {constructor() {this.x = 12;}}
this.globby = true; | globalThis.globby = true; | When used at the top level of a script. |
## CommonJS syntax
| Name | Example | Substitute | Note |
| -------------------------- | ------- | ----------- |----- |
| Nested, undeclared exports | exports.N.X.p = 1; | | Same as expando rules. | | Ignored empty module.exports assignment |exports.N = {};exports.N.X = {};exports.N.X.p = 1;
module.exports = {}; | Delete this line. | People used to write in this in case module.exports was not defined. |
| `this` alias for `module.exports` | this.p = 1; | exports.p = 1; | When used at the top level of a CommonJS module. |
| Multiple assignments narrow with control flow | | Keep the same in most cases. | This now unions instead; most uses have the same type in both branches. | | Single-property access `require` |if (isWindows) {exports.platform = 'win32';} else {
exports.platform = 'posix';}
var readFile = require('fs').readFile; | var { readFile } = require('fs'); | |
| Aliasing of `module.exports` | |var mod = module.exports;mod.x = 1;
module.exports.x = 1; | |
# Component-Level Changes
## Scanner
1. Node positions use UTF8 offsets from the beginning of the file, not UTF16 offsets. Node positions in files with non-ASCII characters will be greater than before.
## Parser
1. Malformed `...T?` at the end of a tuple now fails with a parse error instead of a grammar error.
2. Malformed string ImportSpecifiers (`import x as "OOPS" from "y"`) now contain the string's text instead of an empty identifier.
3. Empty binding elements no longer have a separate kind for OmittedExpression. Instead they have Kind=BindingElement with a nil Initialiser, Name and DotDotDotToken.
4. ShorthandPropertyAssignment no longer includes an EqualsToken as a child when it has an ObjectAssignmentInitializer.
5. JSDoc nodes now include leading whitespace in their location.
6. The parser always parses a JSDocText node for comments in JSDoc. `string` is no longer part of the type of `comment`.
7. In cases where Strada did produce a JSDocText node, Corsa no longer (incorrectly) includes all leading and trailing whitespace/asterisks, as well as initial `/**`.
8. JSDocMemberName is now parsed as QualifiedName. These two nodes previously only differed by type, and now QualifiedName has a much less restrictive type for its left child.
JSDoc types are parsed in normal type annotation position but show a grammar error. Corsa no longer parses the JSDoc types below, giving a parse error instead of a grammar error.
1. No Closure `function(string,string): void` types.
2. No JSDoc standalone `?` type.
3. No JSDoc module namepaths: `module:folder/file.C`
Corsa no longer parses the following JSDoc tags with a specific node type. They now parse as generic JSDocTag nodes.
1. `@class`/`@constructor`
2. `@author`
3. `@enum`
## Checker
### Miscellaneous
#### Error reporting under `--skipLibCheck`
In TypeScript 6, conflicting declarations would sometimes only error in one declaration involved in the conflict.
In TypeScript 7, conflicting declarations now consistently error in all contributing sites.
This means some projects with errors previously fully silenced by `--skipLibCheck` will now correctly see declaration conflict errors in non-.d.ts files.
#### Template literal type inference pulls off a full Unicode code point for empty placeholders.
When inferring through a template literal type with an empty delimiter, Corsa consumes a full Unicode code point rather than a single UTF-16 code unit.
This diverges from Strada, which advances one UTF-16 code unit at a time and therefore splits a supplementary-plane character such as an emoji into its surrogate halves:
```ts
type Head