-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[API Question] Parentheses affects declaration emit. Intentional? #32824
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
Comments
I don't think this is intentional - we normally skip past parens in anywhere where we traverse structure, I'm guessing that when we assign an alias symbol for the mapped type, we're neglecting to do so. It's worth noting though, that even if we patch this, the following: type InvalidKeys3<K extends string|number|symbol> = {
"0": { [P in K]? : never }
}["0"]; Is probably still going to work as a way to avoid giving the mapped type an alias without changing its meaning. |
Ooooooo I just learned a new trick! |
If you put anything other than a constant in that index position, you best name that object you're indexing into, y'hear? I am not responsible for how ugly your printback types get once you start immediately switch-indexing on anonymous objects. |
Also, I think this parentheses thing might partially be the cause of my other emit problems like in, Or maybe even, Because, well, I always use parentheses for complex type aliases. @keithlayne Look! A world where unnecessary parentheses crashes your code! I didn't even need 400+ parentheses this time! The compiler when I add one parentheses, I am One Parentheses Man. |
Uh oh!
There was an error while loading. Please reload this page.
Consider the following snippet,
Playground
I've noticed that, sometimes, the presence/absence of parentheses can change the emitted type declaration. Is this intentional? If so, are there set rules for it? Can this behaviour be relied upon?
There are times where one would want the type to be expanded. And other times where one would not want the type to be expanded.
Having control over it would be nice. (I know I've wanted control over it plenty of times).
I have encountered this discrepancy multiple times but this is the most recent example,
(that inspired me to finally make this issue).
#20863 (comment)
The
InvalidKeys
type is not expanded because I did not wrap the type in parentheses.Obligatory @keithlayne , who hates unnecessary parentheses 🚎
The text was updated successfully, but these errors were encountered: