Skip to content

Commit 21d5f1e

Browse files
committed
prefer type-safer/custom Omit vs built-it TS type
* ref microsoft/TypeScript#30825
1 parent 0dbab8f commit 21d5f1e

File tree

25 files changed

+168
-36
lines changed

25 files changed

+168
-36
lines changed

.eslintrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 2018,
4+
"sourceType": "module"
5+
},
6+
"extends": [
7+
"./linting-extending/eslint/typescript-eslint.json"
8+
]
9+
}

.lintstagedrc.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
22
"*.ts": [
33
"import-sort --write",
4-
"yarn run lint:ts:base --fix",
5-
"git add"
6-
],
7-
"*.js": [
8-
"yarn run lint:js:base --fix",
4+
"yarn run lint:ts:base:tslint --fix",
5+
"yarn run lint:ts:base:eslint --fix",
96
"git add"
107
]
118
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"plugins": [
4+
"@typescript-eslint"
5+
],
6+
"rules": {
7+
"@typescript-eslint/ban-types": [
8+
"error",
9+
{
10+
"types": {
11+
"Omit": "Prefer `Skip` to built-in TS `Omit` type."
12+
}
13+
}
14+
]
15+
}
16+
}

tslint-extending/codelyzer.json renamed to linting-extending/tslint/codelyzer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"rulesDirectory": [
3-
"./../node_modules/codelyzer"
3+
"./../../node_modules/codelyzer"
44
],
55
"rules": {
66
"directive-selector": [

tslint-extending/tslint-consistent-codestyle.json renamed to linting-extending/tslint/tslint-consistent-codestyle.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"rulesDirectory": [
3-
"./../node_modules/tslint-consistent-codestyle/rules"
3+
"./../../node_modules/tslint-consistent-codestyle/rules"
44
],
55
"rules": {
66
"early-exit": [

tslint-extending/tslint-eslint-rules.json renamed to linting-extending/tslint/tslint-eslint-rules.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"rulesDirectory": [
3-
"./../node_modules/tslint-eslint-rules/dist/rules"
3+
"./../../node_modules/tslint-eslint-rules/dist/rules"
44
],
55
"rules": {
66
"object-curly-spacing": [

tslint-extending/tslint-rules-bunch.json renamed to linting-extending/tslint/tslint-rules-bunch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"rulesDirectory": [
3-
"./../node_modules/tslint-rules-bunch/rules"
3+
"./../../node_modules/tslint-rules-bunch/rules"
44
],
55
"rules": {
66
"no-import-zones": [

package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
"electron-builder:dist:linux:pacman": "electron-builder --x64 --linux pacman",
5656
"electron-builder:dist:linux:rpm": "electron-builder --x64 --linux rpm",
5757
"lint": "npm-run-all lint:sass lint:code",
58-
"lint:code": "npm-run-all lint:js lint:ts",
59-
"lint:js:base": "tslint",
60-
"lint:js": "yarn run lint:js:base \"./src/**/*.js\" \"./*.js\"",
58+
"lint:code": "npm-run-all lint:ts:tslint lint:ts:eslint",
6159
"lint:sass": "sass-lint -v -q -c ./sass-lint.yml",
62-
"lint:ts:base": "tslint -p ./tsconfig.json",
63-
"lint:ts": "yarn run lint:ts:base \"./src/**/*.ts\" \"./scripts/**/*.ts\" \"./webpack/**/*.ts\"",
60+
"lint:ts:base:tslint": "tslint -p ./tsconfig.json",
61+
"lint:ts:base:eslint": "eslint",
62+
"lint:ts:tslint": "yarn run lint:ts:base:tslint \"./src/**/*.ts\" \"./scripts/**/*.ts\" \"./webpack/**/*.ts\"",
63+
"lint:ts:eslint": "yarn run lint:ts:base:eslint \"./src/**/*.ts\" \"./scripts/**/*.ts\" \"./webpack/**/*.ts\"",
6464
"start:electron": "electron ./app/electron-main.js",
6565
"start:electron:dev": "electron ./app-dev/electron-main.js",
6666
"test:e2e": "cross-env TS_NODE_FILES=true ts-node -r tsconfig-paths/register ./scripts/ava-loader.ts --verbose --filesGlob \"./src/e2e/**/*.{spec,test}.ts\"",
@@ -190,6 +190,8 @@
190190
"@types/webpack-env": "1.13.9",
191191
"@types/webpack-merge": "4.1.5",
192192
"@types/webpack-node-externals": "1.6.3",
193+
"@typescript-eslint/eslint-plugin": "1.11.0",
194+
"@typescript-eslint/parser": "1.11.0",
193195
"app-builder-lib": "20.44.4",
194196
"archiver": "3.0.0",
195197
"ava": "2.1.0",
@@ -209,6 +211,7 @@
209211
"electron": "5.0.6",
210212
"electron-builder": "20.44.4",
211213
"escape-string-regexp": "2.0.0",
214+
"eslint": "6.0.1",
212215
"exports-loader": "0.7.0",
213216
"file-loader": "4.0.0",
214217
"font-awesome": "4.7.0",

src/@types/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {Observable} from "rxjs";
22

3+
import {Omit} from "type-fest";
4+
35
declare global {
46
type Arguments<F extends (...x: any[]) => any> =
57
F extends (...x: infer A) => any ? A : never;
@@ -12,4 +14,6 @@ declare global {
1214
T;
1315

1416
type Mutable<T> = { -readonly [K in keyof T]: T[K]; };
17+
18+
type Skip<T, K extends keyof T> = Omit<T, K>; // eslint-disable-line @typescript-eslint/ban-types
1519
}

src/electron-main/api/endpoints-builders/database/indexing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function buildDbIndexingEndpoints(
9090
}
9191

9292
export const narrowIndexActionPayload: (
93-
payload: Omit<Extract<UnionOf<typeof IPC_MAIN_API_DB_INDEXER_NOTIFICATION_ACTIONS>, { type: "Index" }>["payload"], "uid">,
93+
payload: Skip<Extract<UnionOf<typeof IPC_MAIN_API_DB_INDEXER_NOTIFICATION_ACTIONS>, { type: "Index" }>["payload"], "uid">,
9494
) => typeof payload = (() => {
9595
type Fn = typeof narrowIndexActionPayload;
9696
type Mails = ReturnType<Fn>["add"];

src/electron-main/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const SNAP_CONTAINER = (
2323
);
2424

2525
export const INITIAL_STORES: Readonly<{
26-
config: () => Omit<Config, "jsFlags"> & Required<Pick<Config, "jsFlags">>;
26+
config: () => Skip<Config, "jsFlags"> & Required<Pick<Config, "jsFlags">>;
2727
settings: () => Settings;
2828
}> = Object.freeze({
2929
config: () => {

src/electron-main/database/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const resolveAccountFolders: <T extends keyof FsDb["accounts"]>(account:
4444
export function patchMetadata(
4545
target: FsDbAccount["metadata"],
4646
// TODO TS: use patch: Arguments<IpcMainApiEndpoints["dbPatch"]>[0]["metadata"],
47-
source: Omit<FsDbAccount<"protonmail">["metadata"], "type"> | Omit<FsDbAccount<"tutanota">["metadata"], "type">,
47+
source: Skip<FsDbAccount<"protonmail">["metadata"], "type"> | Skip<FsDbAccount<"tutanota">["metadata"], "type">,
4848
sourceType: "dbPatch" | "loadDatabase",
4949
): boolean {
5050
const logPrefix = `patchMetadata() ${sourceType}`;

src/electron-preload/webview/protonmail/api/build-db-patch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {isLoggedIn, isUpsertOperationType, preprocessError} from "src/electron-p
2020

2121
interface DbPatchBundle {
2222
patch: DbPatch;
23-
metadata: Omit<FsDbAccount<"protonmail">["metadata"], "type">;
23+
metadata: Skip<FsDbAccount<"protonmail">["metadata"], "type">;
2424
}
2525

2626
type BuildDbPatchMethodReturnType = ProtonmailApiScan["ApiImplReturns"]["buildDbPatch"];

src/electron-preload/webview/protonmail/lib/rest/model/response.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface MessageResponse extends Response {
2525
export interface MessagesResponse extends Response {
2626
Total: number;
2727
Limit: number;
28-
Messages: Array<Omit<Message, "Attachments" | "Body" | "Header" | "MIMEType" | "ParsedHeaders" | "ReplyTo" | "ReplyTos" | "SpamScore"> &
28+
Messages: Array<Skip<Message, "Attachments" | "Body" | "Header" | "MIMEType" | "ParsedHeaders" | "ReplyTo" | "ReplyTos" | "SpamScore"> &
2929
{ HasAttachment: NumberBoolean }>;
3030
}
3131

@@ -36,7 +36,7 @@ export interface ContactResponse extends Response {
3636
export interface ContactsResponse extends Response {
3737
Total: number;
3838
Limit: number;
39-
Contacts: Array<Omit<Contact, "Cards" | "ContactEmails">>;
39+
Contacts: Array<Skip<Contact, "Cards" | "ContactEmails">>;
4040
}
4141

4242
export interface LabelsResponse extends Response {

src/electron-preload/webview/protonmail/lib/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function isLoggedIn(): boolean {
3939
}
4040

4141
export const preprocessError: Arguments<typeof buildDbPatchRetryPipeline>[0] = (rawError: any) => {
42-
const sanitizedNgHttpResponse: (Omit<ng.IHttpResponse<"<wiped out>">, "headers"> & { message: string; headers: "<wiped out>" }) | false
42+
const sanitizedNgHttpResponse: (Skip<ng.IHttpResponse<"<wiped out>">, "headers"> & { message: string; headers: "<wiped out>" }) | false
4343
= angularJsHttpResponseTypeGuard(rawError)
4444
? (() => {
4545
const result = {

src/electron-preload/webview/tutanota/api/build-db-patch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {resolveProviderApi} from "src/electron-preload/webview/tutanota/lib/prov
1818

1919
interface DbPatchBundle {
2020
patch: DbPatch;
21-
metadata: Omit<FsDbAccount<"tutanota">["metadata"], "type">;
21+
metadata: Skip<FsDbAccount<"tutanota">["metadata"], "type">;
2222
}
2323

2424
type BuildDbPatchMethodReturnType = TutanotaScanApi["ApiImplReturns"]["buildDbPatch"];

src/electron-preload/webview/tutanota/lib/rest/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function fetchMultipleEntities<T extends BaseEntity<Id | IdTuple>>(
5353
export async function fetchEntitiesRange<T extends BaseEntity<IdTuple>>(
5454
typeRef: TypeRef<T>,
5555
listId: T["_id"][0],
56-
queryParams: Required<Omit<RequestParams, "ids">>,
56+
queryParams: Required<Skip<RequestParams, "ids">>,
5757
): Promise<T[]> {
5858
logger.debug("fetchEntitiesRange()");
5959

@@ -66,7 +66,7 @@ export async function fetchEntitiesRange<T extends BaseEntity<IdTuple>>(
6666
export async function fetchEntitiesRangeUntilTheEnd<T extends BaseEntity<IdTuple>>(
6767
typeRef: TypeRef<T>,
6868
listId: T["_id"][0],
69-
{start, count}: Required<Omit<RequestParams, "ids" | "reverse">>,
69+
{start, count}: Required<Skip<RequestParams, "ids" | "reverse">>,
7070
portionCallback: (entities: T[]) => Promise<void>,
7171
): Promise<void> {
7272
logger.debug("fetchEntitiesRangeUntilTheEnd()");

src/shared/api/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const ENDPOINTS_DEFINITION = {
4242
dbPatch: ActionType.Promise<DbModel.DbAccountPk
4343
& { forceFlush?: boolean }
4444
& { patch: DbPatch }
45-
& { metadata: Omit<FsDbAccount<"protonmail">["metadata"], "type"> | Omit<FsDbAccount<"tutanota">["metadata"], "type"> },
45+
& { metadata: Skip<FsDbAccount<"protonmail">["metadata"], "type"> | Skip<FsDbAccount<"tutanota">["metadata"], "type"> },
4646
DbModel.FsDbAccount["metadata"]>(),
4747

4848
dbGetAccountMetadata: ActionType.Promise<DbModel.DbAccountPk, DbModel.FsDbAccount["metadata"] | null>(),

src/shared/model/database/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const CONTACT_SOCIAL_TYPE = buildEnumBundle({
8383
CUSTOM: "5",
8484
} as const);
8585

86-
export const INDEXABLE_MAIL_FIELDS_STUB_CONTAINER: Readonly<Record<keyof Omit<IndexableMail, "pk">, null>> = {
86+
export const INDEXABLE_MAIL_FIELDS_STUB_CONTAINER: Readonly<Record<keyof Skip<IndexableMail, "pk">, null>> = {
8787
subject: null,
8888
body: null,
8989
sender: null,

src/shared/model/database/view.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface Folder extends Mutable<Model.Folder> {
66
rootConversationNodes: RootConversationNode[];
77
}
88

9-
export interface Mail extends Omit<Model.Mail, "raw" | "body" | "attachments"> {
9+
export interface Mail extends Skip<Model.Mail, "raw" | "body" | "attachments"> {
1010
folders: Folder[];
1111
score?: number;
1212
}

src/web/browser-window/app/model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface GenericWebAccount<C extends AccountConfig, NS extends Notifications> {
2525
loggedInOnce?: boolean;
2626
loginDelayedSeconds?: number;
2727
loginDelayedUntilSelected?: boolean;
28-
fetchSingleMailParams: Omit<Arguments<CommonWebViewApi<AccountType>["fetchSingleMail"]>[0], keyof ZoneApiParameter> | null;
28+
fetchSingleMailParams: Skip<Arguments<CommonWebViewApi<AccountType>["fetchSingleMail"]>[0], keyof ZoneApiParameter> | null;
2929
}
3030

3131
export type WebAccountProtonmail = GenericWebAccount<AccountConfigProtonmail, NotificationsProtonmail>;

src/web/browser-window/app/store/actions/accounts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const ACCOUNTS_ACTIONS = unionize({
2828
TryToLogin: ofType<{ account: WebAccount; webView: Electron.WebviewTag; }>(),
2929
WireUpConfigs: ofType<{ accountConfigs: AccountConfig[] }>(),
3030
PatchGlobalProgress: ofType<{ patch: State["globalProgress"]; }>(),
31-
SelectMailOnline: ofType<Omit<Arguments<CommonWebViewApi<AccountType>["selectMailOnline"]>[0], "zoneName">>(),
31+
SelectMailOnline: ofType<Skip<Arguments<CommonWebViewApi<AccountType>["selectMailOnline"]>[0], "zoneName">>(),
3232
SetFetchSingleMailParams: ofType<{ pk: DbAccountPk }
3333
& Partial<Pick<Exclude<WebAccount["fetchSingleMailParams"], null>, "mailPk">>>(),
3434
FetchSingleMail: ofType<{ account: WebAccount; webView: Electron.WebviewTag; }

src/web/browser-window/app/store/reducers/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type ProgressPatch = Partial<{
2323

2424
type OptionalProps = "keytarSupport" | "electronLocations" | "checkUpdateAndNotify";
2525

26-
export interface State extends fromRoot.State, Partial<Pick<InitResponse, OptionalProps>>, Omit<InitResponse, OptionalProps> {
26+
export interface State extends fromRoot.State, Partial<Pick<InitResponse, OptionalProps>>, Skip<InitResponse, OptionalProps> {
2727
config: Config;
2828
settings: Settings;
2929
progress: ProgressPatch;

tslint.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"extends": [
33
"./node_modules/tslint/lib/configs/recommended",
4-
"./tslint-extending/tslint-eslint-rules.json",
5-
"./tslint-extending/codelyzer.json",
6-
"./tslint-extending/tslint-rules-bunch.json",
7-
"./tslint-extending/tslint-consistent-codestyle.json"
4+
"./linting-extending/tslint/codelyzer.json",
5+
"./linting-extending/tslint/tslint-consistent-codestyle.json",
6+
"./linting-extending/tslint/tslint-eslint-rules.json",
7+
"./linting-extending/tslint/tslint-rules-bunch.json"
88
],
99
"rules": {
1010
"no-unused-variable": false,

0 commit comments

Comments
 (0)