Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Assert when type inference can't find a common supertype #15116

Copy link
Copy link
@nchen63

Description

@nchen63
Issue body actions

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"'.
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.