microsoft / microsoft/TypeScript
Wrong value type is accepted when key is accessed through an object
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 4.3.2
Search Terms:
Code
enum TheKeys {
k1 = 'k1',
k2 = 'k2',
}
const someObj = { someProp: TheKeys.k1 }
const a: { [k in TheKeys]?: { prop: string }} = { [someObj.someProp]: 1 } // no error, but should be
const b: { [k in TheKeys]?: { prop: string }} = { [TheKeys.k1]: 1 } // error as expected
Expected behavior:
(To my understanding) the type error that's generated for b should be generated for a as well.
Actual behavior:
No error is generated for 'a'.
Related Issues:
None that I know of.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example in the linked TypeScript Playground using the reported TypeScript versions. Investigate how computed property keys from object properties are checked against mapped-type value requirements; done when the a example reports the same type error as b and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100