Skip to content

A way to define the opposite of Partial<T> type #18647

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

Closed
Deilan opened this issue Sep 21, 2017 · 3 comments
Closed

A way to define the opposite of Partial<T> type #18647

Deilan opened this issue Sep 21, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@Deilan
Copy link

Deilan commented Sep 21, 2017

We already have Partial<T> and Readonly<T>, which are defined in the following way:

type Partial<T> = {
    [P in keyof T]?: T[P];
};

type Readonly<T> = {
    readonly [P in keyof T]: T[P];
};

It would be great to have a way to define the opposite of Partial<T>, let's say Mandatory<T> or Strict<T>, etc.:

type Mandatory<T> = {
    [P in keyof T]: T[P]!;
    //                  ^
    // note an exclamation mark, which is already used for
    // asserting a var is not undefined nor null
};

Example. Let's say we have IPerson:

interface IPerson {
    name: string;
    age?: number;
}

Partial<IPerson> would look like that:

interface Partial<IPerson> {
    name?: string;
    age?: number;
}

And the Mandatory<IPerson>:

interface Mandatory<IPerson> {
    name: string;
    age: number;
}
@goodmind
Copy link

Looks like duplicate of #12936

@mhegazy
Copy link
Contributor

mhegazy commented Sep 21, 2017

This is actually a duplicate of #15012

@mhegazy mhegazy added the Duplicate An existing issue was already created label Sep 21, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 5, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Oct 5, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants