Skip to content

Commit 75f9920

Browse files
OrtaKingwl
authored andcommitted
Revert "Add related diagnostic to "used before defined" if type is a function that returns a union with undefined (microsoft#33171)" (microsoft#35751)
This reverts commit be960fa.
1 parent 6c5928d commit 75f9920

7 files changed

+1
-366
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20416,26 +20416,7 @@ namespace ts {
2041620416
}
2041720417
}
2041820418
else if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) {
20419-
const diag = error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
20420-
20421-
// See GH:32846 - if the user is using a variable whose type is () => T1 | ... | undefined
20422-
// they may have meant to specify the type as (() => T1 | ...) | undefined
20423-
// This is assumed if: the type is a FunctionType, the return type is a Union, the last constituent of
20424-
// the union is `undefined`
20425-
if (type.symbol && type.symbol.declarations.length === 1 && isFunctionTypeNode(type.symbol.declarations[0])) {
20426-
const funcTypeNode = <FunctionTypeNode>type.symbol.declarations[0];
20427-
const returnType = getReturnTypeFromAnnotation(funcTypeNode);
20428-
if (returnType && returnType.flags & TypeFlags.Union) {
20429-
const unionTypes = (<UnionTypeNode>funcTypeNode.type).types;
20430-
if (unionTypes && unionTypes[unionTypes.length - 1].kind === SyntaxKind.UndefinedKeyword) {
20431-
const parenedFuncType = getMutableClone(funcTypeNode);
20432-
// Highlight to the end of the second to last constituent of the union
20433-
parenedFuncType.end = unionTypes[unionTypes.length - 2].end;
20434-
addRelatedInfo(diag, createDiagnosticForNode(parenedFuncType, Diagnostics.Did_you_mean_to_parenthesize_this_function_type));
20435-
}
20436-
}
20437-
}
20438-
20419+
error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
2043920420
// Return the declared type to reduce follow-on errors
2044020421
return type;
2044120422
}

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,6 @@
11191119
"category": "Error",
11201120
"code": 1375
11211121
},
1122-
11231122
"The types of '{0}' are incompatible between these types.": {
11241123
"category": "Error",
11251124
"code": 2200

tests/baselines/reference/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.errors.txt

Lines changed: 0 additions & 74 deletions
This file was deleted.

tests/baselines/reference/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

tests/baselines/reference/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.symbols

Lines changed: 0 additions & 89 deletions
This file was deleted.

tests/baselines/reference/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.types

Lines changed: 0 additions & 83 deletions
This file was deleted.

tests/cases/compiler/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)