Skip to content

Commit 04187bd

Browse files
author
Andy
authored
fixStrictClassInitialization: Support array initializer (#24810)
1 parent 8c7a9cc commit 04187bd

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/compiler/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3056,12 +3056,12 @@ namespace ts {
30563056
/* @internal */ getSymbolCount(): number;
30573057
/* @internal */ getTypeCount(): number;
30583058

3059+
/* @internal */ isArrayLikeType(type: Type): boolean;
30593060
/**
30603061
* For a union, will include a property if it's defined in *any* of the member types.
30613062
* So for `{ a } | { b }`, this will include both `a` and `b`.
30623063
* Does not include properties of primitive types.
30633064
*/
3064-
/* @internal */ isArrayLikeType(type: Type): boolean;
30653065
/* @internal */ getAllPossiblePropertiesOfTypes(type: ReadonlyArray<Type>): Symbol[];
30663066
/* @internal */ resolveName(name: string, location: Node, meaning: SymbolFlags, excludeGlobals: boolean): Symbol | undefined;
30673067
/* @internal */ getJsxNamespace(location?: Node): string;

src/services/codefixes/fixStrictClassInitialization.ts

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ namespace ts.codefix {
127127

128128
return createNew(createIdentifier(type.symbol.name), /*typeArguments*/ undefined, /*argumentsArray*/ undefined);
129129
}
130+
else if (checker.isArrayLikeType(type)) {
131+
return createArrayLiteral();
132+
}
130133
return undefined;
131134
}
132135
}

tests/cases/fourslash/codeFixClassPropertyInitialization_all_3.ts

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
//// k: AT;
3636
////
3737
//// l: Foo;
38+
////
39+
//// m: number[];
3840
//// }
3941

4042
verify.codeFixAll({
@@ -73,5 +75,7 @@ class T {
7375
k: AT = new AT;
7476
7577
l: Foo = new Foo;
78+
79+
m: number[] = [];
7680
}`
7781
});

0 commit comments

Comments
 (0)