Skip to content

fixStrictClassInitialization: Support array initializer #24810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Jun 8, 2018
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
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3047,12 +3047,12 @@ namespace ts {
/* @internal */ getSymbolCount(): number;
/* @internal */ getTypeCount(): number;

/* @internal */ isArrayLikeType(type: Type): boolean;
/**
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the comment next to the method it actually describes.

* For a union, will include a property if it's defined in *any* of the member types.
* So for `{ a } | { b }`, this will include both `a` and `b`.
* Does not include properties of primitive types.
*/
/* @internal */ isArrayLikeType(type: Type): boolean;
/* @internal */ getAllPossiblePropertiesOfTypes(type: ReadonlyArray<Type>): Symbol[];
/* @internal */ resolveName(name: string, location: Node, meaning: SymbolFlags, excludeGlobals: boolean): Symbol | undefined;
/* @internal */ getJsxNamespace(location?: Node): string;
Expand Down
3 changes: 3 additions & 0 deletions src/services/codefixes/fixStrictClassInitialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ namespace ts.codefix {

return createNew(createIdentifier(type.symbol.name), /*typeArguments*/ undefined, /*argumentsArray*/ undefined);
}
else if (checker.isArrayLikeType(type)) {
return createArrayLiteral();
}
return undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
//// k: AT;
////
//// l: Foo;
////
//// m: number[];
//// }

verify.codeFixAll({
Expand Down Expand Up @@ -73,5 +75,7 @@ class T {
k: AT = new AT;

l: Foo = new Foo;

m: number[] = [];
}`
});