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

Error: Type T cannot be used to index intersection with Record<T, any> #22317

Closed
NaridaL opened this issue Mar 4, 2018 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@NaridaL
Copy link
Contributor

NaridaL commented Mar 4, 2018

TypeScript Version: 2.8.0-dev.20180302

Search Terms: Type cannot be used to index intersection Type cannot be used to index

Code

interface I {a: 1}
function foo<T extends string>(o: I & Record<T, number>, k: T) {
    o[k] // Type 'T' cannot be used to index type 'I & Record<T, number>'.
}
// the following work:
function foo2<T extends string>(o: Record<T, number>, k: T) {
    o[k]
}
// same result, but T different:
function bar<T extends Record<string, number>>(o: I & T, k: keyof T) {
    o[k]
}

Expected behavior:
No errors.
Actual behavior:
Error.

Playground Link: playground

Related Issues:
There's #18538, but that seems to be an issue with keyof, which isn't an used here.

@ahejlsberg
Copy link
Member

Duplicate of #22286. Already fixed in currently nightly build.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Mar 4, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants