Closed
Description
Bug Report
🔎 Search Terms
unknown record
Index signature
🕗 Version & Regression Information
Bug initially found in v4.7.4
Oldest found version with bug v3.5.1 in typescript playground
Bug found in nightly version v4.8.0-dev.20220728
- This changed between versions v3.3.3 and v3.5.1
⏯ Playground Link
Playground link with relevant code
💻 Code
interface OldProps {
name: unknown;
}
type NewProps = Record<string, unknown>;
// or
// type NewProps = { [key:string]:unknown };
function test(oldProps:OldProps) {
const props:NewProps = oldProps;
return props;
}
🙁 Actual behavior
OldProps type is not assignable to NewProps.
Typescript returns the following error:
Type 'OldProps' is not assignable to type 'NewProps'.
Index signature for type 'string' is missing in type 'OldProps'
Error is consistent with old style record syntax.
Error is consistent if OldProps["name"] type is string
or any
Error not found if NewProps = Record<string, any>;
Error also not found if [key:string]:[whatever type]
is added to OldProps (triggers different expected error if type conflicts with name).
🙂 Expected behavior
OldProps type is assignable to NewProps.
Metadata
Metadata
Assignees
Labels
No labels