Skip to content

Unexpected behavior for "keyof" type-check #14576

Closed
@IIIristraM

Description

@IIIristraM

For code sample like

declare type HasSameKeys<T> = { [TKeyes in keyof T]: any };

declare type SingleString = { a: string };

declare const x: {
  a: string;
  b: string;
  c: string
};

declare function check(input: HasSameKeys<SingleString>): void;

check({
  a: 'x',
  b: 'x',
  c: 'x',
});
check(x);

the first check invocation will produce error as expected

[ts]
Argument of type '{ a: string; b: string; c: string; }' is not assignable to parameter of type 'HasSameKeys<SingleString>'.
  Object literal may only specify known properties, and 'b' does not exist in type 'HasSameKeys<SingleString>'.

but the second - will not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions