Skip to content
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

It's possible to create a callable never #42859

Closed
mkantor opened this issue Feb 18, 2021 · 1 comment · Fixed by #42917
Closed

It's possible to create a callable never #42859

mkantor opened this issue Feb 18, 2021 · 1 comment · Fixed by #42917
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@mkantor
Copy link
Contributor

mkantor commented Feb 18, 2021

Bug Report

🔎 Search Terms

call never, callable intersection, intersection call signature, intersection discriminant

🕗 Version & Regression Information

  • This changed between versions 3.8.3 and 3.9.7 (and still happens in 4.1.5 and 4.2.0-beta).

⏯ Playground Link

Playground link with relevant code

💻 Code

declare const f: { (x: string): number, a: "" } & { a: number }
const result: "bad" = f()

🙁 Actual behavior

The above code typechecks! f's type is displayed as never, but it behaves like (...args: any[]) => any.

🙂 Expected behavior

f should either be a real never (and therefore not be callable), or be callable with the specified call signature ((x: string) => number). Probably the former?


This occurs when intersecting a type that has a call signature with another incompatible type, and only if the incompatibility involves a literal type (i.e. when it's a discriminant).

Based on the behavior and affected versions, this is likely related to #36696.

Elaborated playground with commentary and more examples

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 18, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.3.0 milestone Feb 18, 2021
@Maximilian-Seitz
Copy link

This bug also occurs without a call signature in the original portions of the 'never' type.

So this compiles (Playground Link):

declare const f: { a: '' } & { a: 1 }
const result: "bad" = f()

While this doesn't:

declare const f: never
const result: "bad" = f()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants