Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,16 @@ func (tx *DeclarationTransformer) transformPropertyDeclaration(input *ast.Proper
if ast.IsPrivateIdentifier(input.Name()) {
return nil
}
// Remove definite assignment assertion (!) from declaration files
postfixToken := input.PostfixToken
if postfixToken != nil && postfixToken.Kind == ast.KindExclamationToken {
postfixToken = nil
}
return tx.Factory().UpdatePropertyDeclaration(
input,
tx.ensureModifiers(input.AsNode()),
input.Name(),
input.PostfixToken,
postfixToken,
tx.ensureType(input.AsNode(), false),
tx.ensureNoInitializer(input.AsNode()),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@ class Foo {

//// [declarationEmitTypeofThisInClass.d.ts]
declare class Foo {
foo!: string;
bar!: typeof this.foo; //Public property 'bar' of exported class has or is using private name 'this'.(4031)
foo: string;
bar: typeof this.foo; //Public property 'bar' of exported class has or is using private name 'this'.(4031)
}


//// [DtsFileErrors]


declarationEmitTypeofThisInClass.d.ts(2,8): error TS1255: A definite assignment assertion '!' is not permitted in this context.
declarationEmitTypeofThisInClass.d.ts(3,8): error TS1255: A definite assignment assertion '!' is not permitted in this context.


==== declarationEmitTypeofThisInClass.d.ts (2 errors) ====
declare class Foo {
foo!: string;
~
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
bar!: typeof this.foo; //Public property 'bar' of exported class has or is using private name 'this'.(4031)
~
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,7 @@

//// [declarationEmitTypeofThisInClass.d.ts]
declare class Foo {
- foo: string;
foo: string;
- bar: typeof this.foo;
+ foo!: string;
+ bar!: typeof this.foo; //Public property 'bar' of exported class has or is using private name 'this'.(4031)
}
+
+
+//// [DtsFileErrors]
+
+
+declarationEmitTypeofThisInClass.d.ts(2,8): error TS1255: A definite assignment assertion '!' is not permitted in this context.
+declarationEmitTypeofThisInClass.d.ts(3,8): error TS1255: A definite assignment assertion '!' is not permitted in this context.
+
+
+==== declarationEmitTypeofThisInClass.d.ts (2 errors) ====
+ declare class Foo {
+ foo!: string;
+ ~
+!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
+ bar!: typeof this.foo; //Public property 'bar' of exported class has or is using private name 'this'.(4031)
+ ~
+!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
+ }
+
+ bar: typeof this.foo; //Public property 'bar' of exported class has or is using private name 'this'.(4031)
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ declare class B extends A {
x: number;
}
declare class C {
a!: number;
a: number;
b: number;
}
// Repro from #37979
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@
c: () => number;
d: number;
constructor();
@@= skipped -46, +41 lines =@@
x: number;
}
declare class C {
- a: number;
+ a!: number;
@@= skipped -49, +44 lines =@@
a: number;
b: number;
}
+// Repro from #37979
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,28 @@ function f4() {
//// [definiteAssignmentAssertions.d.ts]
// Suppress strict property initialization check
declare class C1 {
a!: number;
a: number;
b: string; // Error
}
// Suppress definite assignment check in constructor
declare class C2 {
a!: number;
a: number;
constructor();
}
// Definite assignment assertion requires type annotation, no initializer, no static modifier
declare class C3 {
a!: number;
b!: number;
static c!: number;
d!: any;
a: number;
b: number;
static c: number;
d: any;
}
// Definite assignment assertion not permitted in ambient context
declare class C4 {
a!: number;
a: number;
}
// Definite assignment assertion not permitted on abstract property
declare abstract class C5 {
abstract a!: number;
abstract a: number;
}
// Suppress definite assignment check for variable
declare function f1(): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,29 @@
//// [definiteAssignmentAssertions.d.ts]
+// Suppress strict property initialization check
declare class C1 {
- a: number;
a: number;
- b: string;
+ a!: number;
+ b: string; // Error
}
+// Suppress definite assignment check in constructor
declare class C2 {
- a: number;
+ a!: number;
a: number;
constructor();
}
+// Definite assignment assertion requires type annotation, no initializer, no static modifier
declare class C3 {
- a: number;
- b: number;
- static c: number;
- d: any;
+ a!: number;
+ b!: number;
+ static c!: number;
+ d!: any;
a: number;
b: number;
static c: number;
d: any;
}
+// Definite assignment assertion not permitted in ambient context
declare class C4 {
- a: number;
+ a!: number;
a: number;
}
+// Definite assignment assertion not permitted on abstract property
declare abstract class C5 {
- abstract a: number;
+ abstract a!: number;
abstract a: number;
}
+// Suppress definite assignment check for variable
declare function f1(): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void type; // Ok

//// [a.d.ts]
declare class A {
a!: string;
a: string;
}
export = A;
//// [b.d.ts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@
A.prototype; // Error
const a = { a: 'a' }; // Ok
void type; // Ok
@@= skipped -8, +8 lines =@@

//// [a.d.ts]
declare class A {
- a: string;
+ a!: string;
}
export = A;
//// [b.d.ts]
@@= skipped -8, +8 lines =@@
@@= skipped -16, +16 lines =@@
}
export = SomeClass;
//// [c.d.ts]
Expand Down
Loading