mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #28071 from pesca/improveCodeFix
Improve code fix for missing members
This commit is contained in:
@@ -185,6 +185,10 @@ namespace ts.codefix {
|
||||
const widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression)));
|
||||
typeNode = checker.typeToTypeNode(widenedType, classDeclaration);
|
||||
}
|
||||
else {
|
||||
const contextualType = checker.getContextualType(token.parent as Expression);
|
||||
typeNode = contextualType ? checker.typeToTypeNode(contextualType) : undefined;
|
||||
}
|
||||
return typeNode || createKeywordTypeNode(SyntaxKind.AnyKeyword);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class C {}
|
||||
//// const x: number = new C().x;
|
||||
|
||||
verify.codeFix({
|
||||
description: "Declare property 'x'",
|
||||
index: 0,
|
||||
newFileContent:
|
||||
`class C {
|
||||
x: number;
|
||||
}
|
||||
const x: number = new C().x;`
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class C {}
|
||||
//// const x: number = new C().x;
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add index signature for property 'x'",
|
||||
index: 1,
|
||||
newFileContent:
|
||||
`class C {
|
||||
[x: string]: number;
|
||||
}
|
||||
const x: number = new C().x;`
|
||||
});
|
||||
@@ -19,7 +19,7 @@ verify.codeFix({
|
||||
index: 0,
|
||||
newFileContent:
|
||||
`interface I {
|
||||
bar: any;
|
||||
bar: number;
|
||||
}
|
||||
|
||||
function f<T>(t: T): number {
|
||||
|
||||
Reference in New Issue
Block a user