-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Bad type checking enum based objects #48569
Comments
Simplified example: type Translation = { [Locale.en_US]: string } | { [Locale.de_DE]: string }
declare const locale: Locale;
const translation: Translation = { [locale]: '' } |
Duplicate of or strongly related to #13948 |
The underlying problem is that we don't have any accurate + performant representation of the type of It's not It's not It's something like |
I'm not sure if it is related, but sounds so. This code:
generates an error:
which sounds strange, because
then there is no error. |
@edrennikov different issue; the problem is that it's legal for you to write enum E {A, B};
const x = {a: E.A};
x.a = E.B; // <- anywhere in your program
const y: {a: E.A} = x; // <- now unsound You can also use |
Thank you, now I understand it! |
Bug Report
π Search Terms
type checking enum based objects
type checking enum params
π Version & Regression Information
Tested on versions (4.6.2, Nightly - v4.7.0-dev.20220405) on playground all failed.
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
TS produces the error:
π Expected behavior
No errors should be produced. In function, we expect locale which is an enum (not string) and TS prevents us from using something different. Thus the returned object should be of an appropriate Translation type.
The text was updated successfully, but these errors were encountered: