Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior for "keyof" type-check #14576

Closed
IIIristraM opened this issue Mar 10, 2017 · 1 comment
Closed

Unexpected behavior for "keyof" type-check #14576

IIIristraM opened this issue Mar 10, 2017 · 1 comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@IIIristraM
Copy link

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.

@RyanCavanaugh
Copy link
Member

Nothing to do with keyof - see the notes in #3823 for why and when that error appears

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Mar 10, 2017
@mhegazy mhegazy closed this as completed Apr 19, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants