Skip to content

Commit 3e70798

Browse files
committed
fix another crash
1 parent 3ffe9db commit 3e70798

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/services/codefixes/addOptionalPropertyUndefined.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ namespace ts.codefix {
8787
else if (isVariableDeclaration(errorNode.parent) && errorNode.parent.initializer) {
8888
return { source: errorNode.parent.initializer, target: errorNode.parent.name };
8989
}
90-
else if (isCallExpression(errorNode.parent) && errorNode.parent.arguments.indexOf(errorNode as Expression) > -1) {
90+
else if (isCallExpression(errorNode.parent)) {
9191
const n = checker.getSymbolAtLocation(errorNode.parent.expression);
92-
if (!n?.valueDeclaration) return undefined;
92+
if (!n?.valueDeclaration || !isFunctionLikeKind(n.valueDeclaration.kind)) return undefined;
9393
if (!isExpression(errorNode)) return undefined;
9494
const i = errorNode.parent.arguments.indexOf(errorNode);
95+
if (i === -1) return undefined;
9596
const name = (n.valueDeclaration as any as SignatureDeclaration).parameters[i].name;
9697
if (isIdentifier(name)) return { source: errorNode, target: name };
9798
}

tests/cases/fourslash/fixExactOptionalUnassignableProperties6.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// @Filename: fixExactOptionalUnassignableProperties6.ts
66
// based on snapshotterInjected.ts in microsoft/playwright
77
//// type Data = {
8-
//// p?: boolean,
8+
//// p?: (x: number) => void,
99
//// };
1010
//// declare function e(o: any): Data;
1111
//// e(101).p = undefined
@@ -18,7 +18,7 @@ verify.codeFix({
1818
index: 0,
1919
newFileContent:
2020
`type Data = {
21-
p?: boolean | undefined,
21+
p?: ((x: number) => void) | undefined,
2222
};
2323
declare function e(o: any): Data;
2424
e(101).p = undefined`,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @strictNullChecks: true
4+
// @exactOptionalPropertyTypes: true
5+
// @Filename: fixExactOptionalUnassignableProperties6.ts
6+
// based on snapshotterInjected.ts in microsoft/playwright
7+
//// class Feh {
8+
//// _requestFinished(error?: string) {
9+
//// this._finishedPromiseCallback({ error/**/ });
10+
//// }
11+
//// private _finishedPromiseCallback: (arg: { error?: string }) => void = () => {};
12+
//// }
13+
verify.codeFixAvailable([ ]);

0 commit comments

Comments
 (0)