-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type alias resolves to different type than placing the type inline #15973
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
When used as a generic, type ExtractedItems<T extends {items?: any}> = ({[K in keyof (T | { items: {} })]: { [key: string]: T[K] }} & { items: {} })["items"]; |
@mhegazy Ahh, well that won't work for us then. We were using that as a (hacky) filter system to say "do this if T has items". Why does Thanks for taking the time to reply, sorry that we're about to be really difficult about it. Reading through the spec, it appeared to say wrapping in a type alias should make no difference. In 3.7 Named Types is says
and similarly 3.10 Type Aliases says
There's no obvious reference in the spec to the behaviour you describe, and nothing in the spec stands out as describing how constraints are used. 3.6.1 Parameter List is the closest we could see to describing this behaviour, but it's not immediately obvious that it accounts for this.
You say
This doesn't appear to be true in the general case though, in fact the whole thing works as we expected it to until the Apologies if there's something obvious we're not getting and wasting your time with here. We recognise that this likely is working as intended, but feel the documentation could use some improvement here as it's certainly not working as we would have intuitively expected. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.3.1, VS 2017 Preview 2
Code
Expected behavior:
extractedInline and extractedWithType should have the same type.
Actual behavior:
extractedInline is typed as expected, extractedWithType is typed as
{}
.If this behaviour IS in some way expected, that's not made clear in the documentation. Our natural assumption is that a type alias used in this manner to provide a level of indirection should not change the type.
The text was updated successfully, but these errors were encountered: