Error: Type cannot be used to index type after two indexes
See original GitHub issueTypeScript Version: 2.7.1, 2.8.0-dev.20180208
Search Terms: Type cannot be used to index type
Code
interface IExample {
foo: {
bar: {
baz: number;
}
}
}
type F = <
name extends keyof IExample,
val extends keyof IExample[name]
>() => IExample[name][val]['baz']; // ← Type '"baz"' cannot be used to index type 'IExample[name][val]'.
Expected behavior: In version 2.7.0-dev.20171115 this code was checking without errors.
Actual behavior: Now in throws error: Type ‘“baz”’ cannot be used to index type ‘IExample[name][val]’.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:19
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Typescript Error: type 'string' can't be used to index type X
I would suggest looking at the answer from LCC below. The problem with Record<> and unconstrained Index Signatures is that you are widening...
Read more >string can't be used to index type - You.com | The AI Search ...
The "Type 'String' cannot be used as an index type" TypeScript error occurs when we use the String type instead of string (lowercase...
Read more >Type 'X' cannot be used as an index type in TypeScript
The error "Type cannot be used as an index type" occurs when we try to use a type that cannot be used to...
Read more >Documentation - Indexed Access Types - TypeScript
const key = "age";. type Age = Person [ key ];. Type 'key' cannot be used as an index type. ... 2749Type 'key'...
Read more >Solved - "Element implicitly has an 'any' type because ...
The error "Element implicitly has an 'any' type because expression of type 'number' can't be used to index type" occurs when we try...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually, it’s really weird! I’m getting type errors, but TS is getting the derived type right anyway!
ERROR in node_modules/@amcharts/amcharts4/.internal/charts/types/XYChart.d.ts(258,33): error TS2344: Type ‘this[“_xAxisRendererType”]’ does not satisfy the constraint ‘AxisRenderer’. Type ‘AxisRendererX’ is not assignable to type ‘AxisRenderer’. Types of property ‘events’ are incompatible. Type ‘SpriteEventDispatcher<AMEvent<AxisRendererX, IAxisRendererXEvents>>’ is not assignable to type ‘SpriteEventDispatcher<AMEvent<this[“_xAxisRendererType”], this[“_xAxisRendererType”][“_events”]>>’. Type ‘AMEvent<AxisRendererX, IAxisRendererXEvents>’ is not assignable to type ‘AMEvent<this[“_xAxisRendererType”], this[“_xAxisRendererType”][“_events”]>’. node_modules/@amcharts/amcharts4/.internal/charts/types/XYChart.d.ts(264,33): error TS2344: Type ‘this[“_yAxisRendererType”]’ does not satisfy the constraint ‘AxisRenderer’. Type ‘AxisRendererY’ is not assignable to type ‘AxisRenderer’. Types of property ‘events’ are incompatible. Type ‘SpriteEventDispatcher<AMEvent<AxisRendererY, IAxisRendererYEvents>>’ is not assignable to type ‘SpriteEventDispatcher<AMEvent<this[“_yAxisRendererType”], this[“_yAxisRendererType”][“_events”]>>’. Type ‘AMEvent<AxisRendererY, IAxisRendererYEvents>’ is not assignable to type ‘AMEvent<this[“_yAxisRendererType”], this[“_yAxisRendererType”][“_events”]>’. node_modules/@amcharts/amcharts4/.internal/charts/types/XYChart.d.ts(503,31): error TS2344: Type ‘this[“_xAxisRendererType”]’ does not satisfy the constraint ‘AxisRenderer’. node_modules/@amcharts/amcharts4/.internal/charts/types/XYChart.d.ts(513,31): error TS2344: Type ‘this[“_yAxisRendererType”]’ does not satisfy the constraint ‘AxisRenderer’. node_modules/@amcharts/amcharts4/.internal/core/utils/Object.d.ts(60,117): error TS2536: Type ‘Key’ cannot be used to index type ‘Object’. node_modules/@amcharts/amcharts4/.internal/core/utils/Object.d.ts(67,109): error TS2536: Type ‘Key’ cannot be used to index type ‘Object’. node_modules/@amcharts/amcharts4/.internal/core/utils/Object.d.ts(76,116): error TS2536: Type ‘Key’ cannot be used to index type ‘Object’. node_modules/@amcharts/amcharts4/.internal/core/utils/Type.d.ts(25,32): error TS2304: Cannot find name ‘Extract’.
Please… Help Me…