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

Intersection with mapped never type allows incompatible optional assignments #19927

Closed
kpdonn opened this issue Nov 10, 2017 · 2 comments
Closed
Labels
Bug A bug in TypeScript
Milestone

Comments

@kpdonn
Copy link
Contributor

kpdonn commented Nov 10, 2017

TypeScript Version: 2.7.0-dev.20171110

Code

declare const a:  {z: string} & {[K in never]: string} 
const b: {z?: number} = a

Expected behavior:
Compile error on the second line because {z?: number} is incompatible with {z: string}

Actual behavior:
No Error

Obviously the code above is nonsensical but I spun this out of a special case in #19869 since that one ended up being about generic function inferences and I realized this is something different.

Some more code examples that make me think my example should have a compile error:

declare const a2: {z: string} & {[K in never]: string}
const b2: {z: number} = a2 
// TS2322: Type '{ z: string; } & {}' is not assignable to type '{ z: number; }'.

declare const a3: {z: string} & {}
const b3: {z?: number} = a3 
// TS2322: Type '{ z: string; }' is not assignable to type '{ z?: number | undefined; }'.

declare const a4: {z: string, y: string} & {[K in never]: string}
const b4: {z?: number, y: string} = a4 
// TS2322: Type '{ z: string; y: string; } & {}' is not assignable to type '{ z?: number | undefined; y: string; }'.
@jcalz
Copy link
Contributor

jcalz commented Nov 25, 2022

Looks like this has been fixed as of TS3.9

@jakebailey
Copy link
Member

Just looking at old issues; this was fixed in #37195 (so, 3.9, as noted above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants