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
type inference error #58097
Comments
• The issue template has not quite been filled out properly; could you fix it, please? • Why do you have • Where is the bug, exactly? If you're expecting function Foo<
T extends StateKey,
U extends keyof State[T][number]
>(stateKey: T, valueKey: U) {
const list = state[stateKey];
list.map((item: State[T][number]) => {
console.log(item[valueKey]);
});
} |
Sorry, my ts skills are still in the novice stage. And why should I add type State[T][number] to annotate item? The type of list is State[T], So shouldn’t the type of item be State[T][number]? |
This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
🔎 Search Terms
Type 'U' cannot be used to index type '{ name: string; capacity: number; } | { name: string; amount: number; }'.
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.4.3#code/JYOwLgpgTgZghgYwgAgMpjpZBvAsAKGWQHcB7KAa2gGcAuHZEOAWwnurClAHMBuZBHAAOiYGACe9EAFdmAI2jIAvgG0AurwJFicKBAAWpadQh0GTVu049+LI+CmyFUZes34lBAhKEp0mCABpCHFkAF5kKnFSGDQMSHcfFAA1OAAbaSCQgB4AFWQIAA9IEAATajiA4PEAPnDIkJjKyBVctRUZeWgNL3wEUhAOZA4A+n8sCLxCEnIqKDMVLSJzFjZkAHIAKVJ9EHWAGgFhUQl6AEZlfaWibEZV+nXc0mYDo5EEMUlkC6Ur6bU-tpdAYjCYFtcVpYNgB1UikUqvOzSBzIAAMlwhtwsa3W6AGEERzHsYHo6N+SwBBCU7gIMGRCDAwAGyAAYnC8gVihAyhVxllxIcAKr1VIZfl5Go1AAUI0g1XouUOADd0pl5chBQBKHBLfqDMDINLAIYRWUQFRm6o9aZGjgAOmYwilUrEEGY2rCdSmywEA2opDSEDtaVI3BdkGYKhVYqtmvcRCUcapBCAA
💻 Code
🙁 Actual behavior
Type 'U' cannot be used to index type '{ name: string; capacity: number; } | { name: string; amount: number; }'.
🙂 Expected behavior
no error report
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: