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

Add the Omit helper type #30552

Merged
merged 4 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4507,6 +4507,7 @@ namespace FourSlashInterface {
typeEntry("Record"),
typeEntry("Exclude"),
typeEntry("Extract"),
typeEntry("Omit"),
typeEntry("NonNullable"),
typeEntry("Parameters"),
typeEntry("ConstructorParameters"),
Expand Down
5 changes: 5 additions & 0 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,11 @@ type Exclude<T, U> = T extends U ? never : T;
*/
type Extract<T, U> = T extends U ? T : never;

/**
* Construct a type with the properties of T except for those in type K.
*/
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

/**
* Exclude null and undefined from T
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ const myStoreConnect: Connect = function(
mergeProps,
options,
);
};
};

export {};


//// [circularlySimplifyingConditionalTypesNoCrash.js]
"use strict";
exports.__esModule = true;
var myStoreConnect = function (mapStateToProps, mapDispatchToProps, mergeProps, options) {
if (options === void 0) { options = {}; }
return connect(mapStateToProps, mapDispatchToProps, mergeProps, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,6 @@ const myStoreConnect: Connect = function(

);
};

export {};

Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,6 @@ const myStoreConnect: Connect = function(

);
};

export {};

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ type Omit1<U, K extends keyof U> = Pick<U, Diff<keyof U, K>>;
type Omit2<T, K extends keyof T> = {[P in Diff<keyof T, K>]: T[P]};

type O = Omit<{ a: number, b: string }, 'a'>
const o: O = { b: '' }
export const o: O = { b: '' }


//// [indexedAccessRetainsIndexSignature.js]
var o = { b: '' };
"use strict";
exports.__esModule = true;
exports.o = { b: '' };
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ type O = Omit<{ a: number, b: string }, 'a'>
>a : Symbol(a, Decl(indexedAccessRetainsIndexSignature.ts, 8, 15))
>b : Symbol(b, Decl(indexedAccessRetainsIndexSignature.ts, 8, 26))

const o: O = { b: '' }
>o : Symbol(o, Decl(indexedAccessRetainsIndexSignature.ts, 9, 5))
export const o: O = { b: '' }
>o : Symbol(o, Decl(indexedAccessRetainsIndexSignature.ts, 9, 12))
>O : Symbol(O, Decl(indexedAccessRetainsIndexSignature.ts, 6, 67))
>b : Symbol(b, Decl(indexedAccessRetainsIndexSignature.ts, 9, 14))
>b : Symbol(b, Decl(indexedAccessRetainsIndexSignature.ts, 9, 21))

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type O = Omit<{ a: number, b: string }, 'a'>
>a : number
>b : string

const o: O = { b: '' }
export const o: O = { b: '' }
>o : Pick<{ a: number; b: string; }, "b">
>{ b: '' } : { b: string; }
>b : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ const Test1 = connect(
null,
mapDispatchToProps
)(TestComponent);

export {};


//// [reactReduxLikeDeferredInferenceAllowsAssignment.js]
Expand Down Expand Up @@ -196,6 +198,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}
};
var _this = this;
exports.__esModule = true;
var simpleAction = function (payload) { return ({
type: "SIMPLE_ACTION",
payload: payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,5 @@ const Test1 = connect(
)(TestComponent);
>TestComponent : Symbol(TestComponent, Decl(reactReduxLikeDeferredInferenceAllowsAssignment.ts, 134, 1))

export {};

Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,5 @@ const Test1 = connect(
)(TestComponent);
>TestComponent : typeof TestComponent

export {};

Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ const myStoreConnect: Connect = function(
mergeProps,
options,
);
};
};

export {};
2 changes: 1 addition & 1 deletion tests/cases/compiler/indexedAccessRetainsIndexSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ type Omit1<U, K extends keyof U> = Pick<U, Diff<keyof U, K>>;
type Omit2<T, K extends keyof T> = {[P in Diff<keyof T, K>]: T[P]};

type O = Omit<{ a: number, b: string }, 'a'>
const o: O = { b: '' }
export const o: O = { b: '' }
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,5 @@ const Test1 = connect(
null,
mapDispatchToProps
)(TestComponent);

export {};