Ask Your Question
4

Why does the use of a generic type as an object index fail, causing the error message ts2536?

asked 2022-10-15 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-05-20 15:00:00 +0000

huitzilopochtli gravatar image

The use of a generic type as an object index fails because the object keys have to be of a specific type, and generic types may have multiple possible types that cannot be used as object keys. This causes the TypeScript compiler to generate the error message ts2536, indicating that the type cannot be used as an index type. To fix this error, a specific type needs to be used as the object key, or the generic type needs to be narrowed down to a specific type.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-15 11:00:00 +0000

Seen: 12 times

Last updated: May 20 '21