mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
c517aa08a8
## Summary - Align auto-accessor definite assignment assertions with TypeScript. - Report TS1263 when an accessor has both `!` and an initializer. - Report TS1264 when an accessor has `!` but no type annotation. - Report TS1255 for typed definite assertions in static, abstract, and ambient contexts. - Highlight only the `!` token, matching TypeScript. fixes #24503. ## TypeScript behavior Given: ```ts class A { accessor missingType!; // ^: TS1264: Declarations with definite assignment assertions must also have type annotations. accessor initialized! = 1; // ^: TS1263: Declarations with initializers cannot also have definite assignment assertions. accessor typed!: number; // ^: valid static accessor staticTyped!: number; // ^: TS1255: A definite assignment assertion '!' is not permitted in this context. } ``` TypeScript treats auto-accessors as property declarations and applies the following grammar check: https://github.com/microsoft/TypeScript/blob/637d5746b70257028fb95aad32ddec6b26ab0a14/src/compiler/checker.ts#L53443-L53452 This establishes the diagnostic precedence: 1. An initializer produces TS1263. 2. Otherwise, a missing type annotation produces TS1264. 3. Otherwise, an invalid context produces TS1255.
23 lines
474 B
TypeScript
23 lines
474 B
TypeScript
class Basic {
|
|
accessor noType!;
|
|
accessor initialized! = 1;
|
|
accessor typed!: number;
|
|
static accessor staticTyped!: number;
|
|
static accessor staticNoType!;
|
|
static accessor staticInitialized! = 1;
|
|
}
|
|
|
|
abstract class Abstract {
|
|
abstract accessor value!: number;
|
|
}
|
|
|
|
declare class Ambient {
|
|
accessor value!: number;
|
|
}
|
|
|
|
class DeclareMember {
|
|
declare accessor typed!: number;
|
|
declare accessor untyped!;
|
|
declare accessor initialized! = 1;
|
|
}
|