Skip to content

Unspecified required types #12791

Closed
Closed
@falsandtru

Description

@falsandtru

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

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