Skip to content

Can't assign never as object value to conditional type #56578

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

Closed
vpzomtrrfrt opened this issue Nov 28, 2023 · 3 comments
Closed

Can't assign never as object value to conditional type #56578

vpzomtrrfrt opened this issue Nov 28, 2023 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@vpzomtrrfrt
Copy link

πŸ”Ž Search Terms

"never conditional not assignable"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about never

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.0-dev.20231128#code/C4TwDgpgBAYg9nAPAFQHxQLxQN4DcCGANgK4QBcUyAvgNwBQokUAQvgE4rpbJQQAewCADsAJgGcoxURABmASyEQRUAPw4CJcpSpQKeIqQrV6dGVIDGwOXCFQARu04AKAJQ46UT1HM2xwKHwU8EhomOoGWgAMUPgSirgQbLQeXj5CflAgFKwcoVj6mhTRsVDxicle3r7+AF7ZjnlQxXEQCWz0VEA

πŸ’» Code

type Foo<T> = {value: T};
type Bar<T> = T extends undefined ? {value: T} : {value: T};

function bar<T>() {
    const x: Foo<T> = {value: 0 as never};
    const y: Bar<T> = {value: 0 as never};
    const z: Bar<T> = 0 as never;
}

πŸ™ Actual behavior

Type '{ value: never; }' is not assignable to type 'Bar<T>'. on the const y line, despite the fact that Bar should be equivalent to Foo

πŸ™‚ Expected behavior

I expect to be able to assign never to everything

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

MartinJohns commented Nov 28, 2023

Resolving of conditional types involving unbound type arguments is deferred. The compiler doesn't know what type T is, so it can't resolve the conditional type.

This should really be added to the FAQ, given how often this gets reported (a lot).

I expect to be able to assign never to everything

You are. But in the case of y you're not trying to assign never, you're trying to assign an object.

@RyanCavanaugh
Copy link
Member

Duplicate #51488, others

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 29, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants