microsoft / microsoft/TypeScript
Common property check isn't performed when the target has any index signature
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
common property check weak type index signature
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type Delay<TDelay extends string> = TDelay | number;
interface MachineConfig<TDelay extends string> {
types?: unknown;
after?: {
[K in Delay<TDelay>]?: number;
};
}
declare function test<
TDelay extends string,
TConfig extends MachineConfig<TDelay>,
>(config: { types: { delays: TDelay } } & TConfig): void;
test({
types: {} as {
delays: "one second" | "one minute";
},
after: {
// @ts-expect-error
oops_this_is_unknown_delay: 100,
},
});
function test2<T extends { [x: `id-${number}`]: string }>(a: T) {}
test2({
// @ts-expect-error
random: true,
});
function test3<T extends { [x: symbol]: string }>(a: T) {}
test3({
// @ts-expect-error
random: true,
});
🙁 Actual behavior
No errors are raised here since index signatures turn off the common property check completely.
🙂 Expected behavior
I don't have a good intuition about the common property check so I'm not sure if all of those 3 examples should be treated as bugs/possible improvements. I think though that especially the first one is surprising because I have a list of 2 concrete string properties that are meant to be allowed there and yet the unrelated~ index signature for numbers turns off this check, leading to accidental problems at runtime.
Additional information about the issue
No response
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 with the linked TypeScript Playground and compare the three examples in test, test2, and test3. Trace how the common property check behaves with mapped, template-literal, and symbol index signatures; done means the intended diagnostics and expected treatment of all three cases are established.
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