Closed
Description
TypeScript Version: 2.2.2
Code
// A *self-contained* demonstration of the problem follows...
function isEqual<T>(a: T, b: T) { return a === b; };
type Gut = { shape: "defined" | undefined };
let gut: Gut;
gut = { shape: undefined };
isEqual(gut.shape, "defined");
// isEqual("defined", gut.shape); // uncomment this line and comment out line above to get invalid supertype error
Expected behavior:
Actual behavior:
/usr/local/lib/node_modules/typescript/lib/tsc.js:51296
throw e;
^
Error: Debug Failure. False expression: If there is no common supertype, each type should have a downfallType
at Object.assert (/usr/local/lib/node_modules/typescript/lib/tsc.js:1888:23)
at reportNoCommonSupertypeError (/usr/local/lib/node_modules/typescript/lib/tsc.js:26948:26)
at resolveCall (/usr/local/lib/node_modules/typescript/lib/tsc.js:30747:21)
at resolveCallExpression (/usr/local/lib/node_modules/typescript/lib/tsc.js:30869:20)
at resolveSignature (/usr/local/lib/node_modules/typescript/lib/tsc.js:31024:28)
at getResolvedSignature (/usr/local/lib/node_modules/typescript/lib/tsc.js:31041:26)
at checkCallExpression (/usr/local/lib/node_modules/typescript/lib/tsc.js:31057:29)
at checkExpressionWorker (/usr/local/lib/node_modules/typescript/lib/tsc.js:32249:28)
at checkExpression (/usr/local/lib/node_modules/typescript/lib/tsc.js:32205:42)
at checkExpressionStatement (/usr/local/lib/node_modules/typescript/lib/tsc.js:33857:13)
or if uncommenting out last line and commenting out 2nd to last line:
test.ts(8,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate '"defined"' is not a valid type argument because it is not a supertype of candidate '"defined" | undefined'.
Type 'undefined' is not assignable to type '"defined"'.