Skip to content

Record types are not enforced strictly enough when passed as parametersΒ #62560

@NVP12345

Description

@NVP12345

πŸ”Ž Search Terms

record type enforcement strict parameters

πŸ•— Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about Record, Exclude, etc.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAHjAvDAFABwIYCcMFsBcMASgKahYAmAPGAK64BGJWANDHY8wHwCUSXMAN4BfANwAocQHopMAGIYAlgBsIbDBBgk4aMlBIVxcFIJhQAFooiEA5FZtswIKLYwOYWMiEq2A-DZhhHkkZGAAFDQgSTUUwck9gKGUAT3FQSFhkpCEzS2sYOwh3JxcCtzYE7wo-ALEjFGSeCSA

πŸ’» Code

const recordFunction = (param: Record<number, number>) => {};

recordFunction({ this: 'is', not: 'a', record: '?' }); // Fails, as expected

const y = { this: 'is', not: 'a', record: '?' };
recordFunction(y); // Passes incorrectly

πŸ™ Actual behavior

No error is raised by TypeScript. This allows for almost any object to be passed to a function that expects a Record, which will miss finding developer errors and may result in significant inconsistencies at runtime.

πŸ™‚ Expected behavior

I expect an error be raised.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions