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

Unspecified required types #12791

Closed
falsandtru opened this issue Dec 9, 2016 · 4 comments
Closed

Unspecified required types #12791

falsandtru opened this issue Dec 9, 2016 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@falsandtru
Copy link
Contributor

falsandtru commented Dec 9, 2016

Now we can make the required types using parentheses or separated definitions. Is this the spec?

TypeScript Version: master

Code

type PersonStrict = { name: string, age: number };
type PersonPartial = { name?: string, age?: number };
type Required<T> = { [K in (keyof T)]: T[K] };
const person: Required<PersonPartial> = { name: "iwata" };

or

...
type Keys<T> = keyof T;
type Required<T> = { [K in Keys<T>]: T[K] };
const person: Required<PersonPartial> = { name: "iwata" };
index.ts(4,7): error TS2322: Type '{ name: string; }' is not assignable to type 'Required<PersonPartial>'.
  Property 'age' is missing in type '{ name: string; }'.

cc @ahejlsberg @weswigham

@ahejlsberg
Copy link
Member

No, that is an unintended effect and it will no longer be the case with #12826. Also, it doesn't really work because you can't get rid of the undefined that was added to each property type by Partial<T>.

@falsandtru
Copy link
Contributor Author

I see, thanks for the answer.

@falsandtru
Copy link
Contributor Author

Do you fix this effect? This will be a breaking change after many users found this and use as a hack.

@falsandtru falsandtru reopened this Dec 10, 2016
@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 12, 2016
@RyanCavanaugh
Copy link
Member

We reserve the right to make back compat breaks for things that are effectively bugs. "Things behaved differently when I added parentheses which should have been meaningless" isn't something anyone should have taken a dependency on.

@mhegazy mhegazy closed this as completed Apr 21, 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

4 participants