🔎 Search Terms
record, generics, object literal
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Generics
⏯ Playground Link
https://tsplay.dev/mq0kQN
💻 Code
declare function forEach<T extends string | number | symbol>(
data: { [a in T]: unknown },
cb: (x: T) => unknown
): void;
declare let record: Record<string, unknown>;
forEach(record, key => {})
// ^?
declare let obj: { [a: string]: unknown };
forEach(obj, key => {})
// ^?
🙁 Actual behavior
key for record: Record<string, unknown> is inferred as string type
key for { [a: string]: unknown } is inferred as string | number type
🙂 Expected behavior
both key should be inferred as the same type, i.e. string type.
Additional information about the issue
No response
🔎 Search Terms
record, generics, object literal
🕗 Version & Regression Information
⏯ Playground Link
https://tsplay.dev/mq0kQN
💻 Code
🙁 Actual behavior
keyforrecord: Record<string, unknown>is inferred asstringtypekeyfor{ [a: string]: unknown }is inferred asstring | numbertype🙂 Expected behavior
both
keyshould be inferred as the same type, i.e.stringtype.Additional information about the issue
No response