Skip to content

Commit 1dafd09

Browse files
author
Orta
authored
Revert "Add related diagnostic to "used before defined" if type is a function that returns a union with undefined (#33171)" (#35751)
This reverts commit be960fa.
1 parent 6e3ab15 commit 1dafd09

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

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)