-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
compile error in 2.7 for indexed types work with generics #21529
Comments
confirmed it exists on version |
Maybe related to #21368 |
looks like a duplicate of #21369 |
I 've read your post on #21369
but it's not the same case i think. in ts like in ts like BTW, I notice that you labeled #21369 with |
playground |
considering
In my opinion, it's a bug in type system @mhegazy |
This seems to be a problem with the non-null assertion operator when used on the result of a computed member expression. This problem was not present on 2.7.0-rc; seems to be new to 2.7.1. import * as types from './types'
interface PreloadTypes {
post: types.PreloadPostData
user: types.PreloadUserData
}
interface GlobalPreload {
post?: { [id: string]: PreloadTypes['post'] }
user?: { [id: string]: PreloadTypes['user'] }
}
declare var preload: GlobalPreload
export function getPreload<TKind extends keyof PreloadTypes> (kind: TKind, id: string): PreloadTypes[TKind]|undefined {
if (kind in preload && id in preload[kind]) {
return preload[kind]![id]
// [id] access errors because it's indexing a possibly undefined object
}
} Changing the line to, for example, be Changing the access to be const kindPreload = preload[kind]!
return kindPreload[id] instead still causes a build error on the second linke because Finally, adding the Also note that removing the |
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.7.1
Search Terms: typer inference, indexed types, generics
Code
with tsconfig (removed other configs)
Expected behavior:
No Error in
2.7
&2.6
Actual behavior:
No Error in
2.6
but in
2.7
it throwsProperty 'concat' does not exist on type 'Foo[SomeName]'
FYI. I found some ways to make this error disappear. I think there must be something related but I can't tell.
undefined
type inFoo
's valueconst newFoo = foo[name]
name
to bestring
The text was updated successfully, but these errors were encountered: