mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 03:20:56 -06:00
quick fix for a nullable missing callback function (#51743)
This commit is contained in:
parent
9e845d2248
commit
0c09d2f172
@ -330,7 +330,7 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
|
||||
}
|
||||
|
||||
if (isIdentifier(token)) {
|
||||
const type = checker.getContextualType(token);
|
||||
const type = checker.getContextualType(token)?.getNonNullableType();
|
||||
if (type && getObjectFlags(type) & ObjectFlags.Anonymous) {
|
||||
const signature = firstOrUndefined(checker.getSignaturesOfType(type, SignatureKind.Call));
|
||||
if (signature === undefined) return undefined;
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @strict: true
|
||||
|
||||
////interface Foo {
|
||||
//// a: ((e: any) => void) | null;
|
||||
////}
|
||||
////
|
||||
////const foo: Foo = {
|
||||
//// a: fn
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: [ts.Diagnostics.Add_missing_function_declaration_0.message, "fn"],
|
||||
newFileContent:
|
||||
`interface Foo {
|
||||
a: ((e: any) => void) | null;
|
||||
}
|
||||
|
||||
const foo: Foo = {
|
||||
a: fn
|
||||
}
|
||||
|
||||
function fn(e: any): void {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
`
|
||||
});
|
||||
@ -0,0 +1,29 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @strict: true
|
||||
|
||||
////interface Foo {
|
||||
//// a?: ((e: any) => void);
|
||||
////}
|
||||
////
|
||||
////const foo: Foo = {
|
||||
//// a: fn
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: [ts.Diagnostics.Add_missing_function_declaration_0.message, "fn"],
|
||||
newFileContent:
|
||||
`interface Foo {
|
||||
a?: ((e: any) => void);
|
||||
}
|
||||
|
||||
const foo: Foo = {
|
||||
a: fn
|
||||
}
|
||||
|
||||
function fn(e: any): void {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
`
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user