Skip to content

Revert microsoft/TypeScript#33171 #35751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20418,26 +20418,7 @@ namespace ts {
}
}
else if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) {
const diag = error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));

// See GH:32846 - if the user is using a variable whose type is () => T1 | ... | undefined
// they may have meant to specify the type as (() => T1 | ...) | undefined
// This is assumed if: the type is a FunctionType, the return type is a Union, the last constituent of
// the union is `undefined`
if (type.symbol && type.symbol.declarations.length === 1 && isFunctionTypeNode(type.symbol.declarations[0])) {
const funcTypeNode = <FunctionTypeNode>type.symbol.declarations[0];
const returnType = getReturnTypeFromAnnotation(funcTypeNode);
if (returnType && returnType.flags & TypeFlags.Union) {
const unionTypes = (<UnionTypeNode>funcTypeNode.type).types;
if (unionTypes && unionTypes[unionTypes.length - 1].kind === SyntaxKind.UndefinedKeyword) {
const parenedFuncType = getMutableClone(funcTypeNode);
// Highlight to the end of the second to last constituent of the union
parenedFuncType.end = unionTypes[unionTypes.length - 2].end;
addRelatedInfo(diag, createDiagnosticForNode(parenedFuncType, Diagnostics.Did_you_mean_to_parenthesize_this_function_type));
}
}
}

error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
// Return the declared type to reduce follow-on errors
return type;
}
Expand Down
1 change: 0 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@
"category": "Error",
"code": 1375
},

"The types of '{0}' are incompatible between these types.": {
"category": "Error",
"code": 2200
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.