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

[exactOptionalPropertyTypes] Unexpected 'undefined' arises in error message #60712

Open
ghostinpeace opened this issue Dec 7, 2024 · 1 comment · May be fixed by #60716
Open

[exactOptionalPropertyTypes] Unexpected 'undefined' arises in error message #60712

ghostinpeace opened this issue Dec 7, 2024 · 1 comment · May be fixed by #60716
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@ghostinpeace
Copy link

ghostinpeace commented Dec 7, 2024

🔎 Search Terms

"not assignable", "never", "undefined", "exactOptionalPropertyTypes"

🕗 Version & Regression Information

4.3.5
'undefined' error instead of 'never' ; the value undefined is considered valid
4.4.4, 5.0.4
Expected behavior
5.1.6, 5.7.2
'undefined' error instead of 'never' ; the value undefined triggers the 'never' message
Nightly
not available when testing

⏯ Playground Link

https://www.typescriptlang.org/play/?exactOptionalPropertyTypes=true&ts=5.7.2#code/C4TwDgpgBAKlC8UCwAoKUDeUCGAuKAdgK4C2ARhAE4A0UZA-PgRAG5VQC+UAPqultkaFWVWmSakKlTgG5UqAMYB7AgGdgUYPjiIMfHPgAM1feKiHUHGUA

💻 Code

--exactOptionalPropertyTypes

type T = 
  { a: number, b?: never } |
  { a?: never, b: number };

const t: T = { //  Types of property 'b' are incompatible. Type 'number' is not assignable to type 'undefined'
  a: 0,
  b: 0
};

🙁 Actual behavior

Type 'number' is not assignable to type 'undefined' is not relevant, since undefined cannot be the type of the t[b].

🙂 Expected behavior

The error should be about type 'number' not being assignable to type 'never'.
It is correctly displayed if the value undefined is used (after the regression at least).

@jcalz

This comment has been minimized.

@ghostinpeace ghostinpeace changed the title not assignable to 'undefined', instead of 'never' [exactOptionalPropertyTypes} Unexpected 'undefined' arises in error message Dec 7, 2024
@ghostinpeace ghostinpeace changed the title [exactOptionalPropertyTypes} Unexpected 'undefined' arises in error message [exactOptionalPropertyTypes] Unexpected 'undefined' arises in error message Dec 7, 2024
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Dec 11, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
3 participants