From e42d18883bd689f5f14ec908272ffd65b64b613b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:19:45 -0700 Subject: [PATCH 1/2] Enable @typescript-eslint/ban-types --- .eslintrc.json | 11 ++++++++++- src/compiler/sys.ts | 2 +- src/harness/fourslashImpl.ts | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 30e6bb6ef2f65..3e172986d22e8 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -79,9 +79,18 @@ "@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-non-null-asserted-optional-chain": "off", "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/ban-types": [ + "error", + { + "extendDefaults": true, + "types": { + "Symbol": false, // This is theoretically good, but ts-eslint appears to mistake our declaration of Symbol for the global Symbol type. + "{}": false // {} is a totally useful and valid type. + } + } + ], // Todo: For each of these, investigate whether we want to enable them ✨ - "@typescript-eslint/ban-types": "off", "no-case-declarations": "off", "no-cond-assign": "off", "no-constant-condition": "off", diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index b7b73d4158312..db12d3a6dd96e 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1711,7 +1711,7 @@ export let sys: System = (() => { function bufferFrom(input: string, encoding?: string): Buffer { // See https://github.com/Microsoft/TypeScript/issues/25652 - return Buffer.from && (Buffer.from as Function) !== Int8Array.from + return Buffer.from && Buffer.from !== Int8Array.from ? Buffer.from(input, encoding) : new Buffer(input, encoding); } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index b6ab758e7ebe3..6927acdbd3afa 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -442,11 +442,11 @@ export class TestState { for (const k of keys) { const key = k as keyof typeof ls; if (cacheableMembers.indexOf(key) === -1) { - proxy[key] = (...args: any[]) => (ls[key] as Function)(...args); + proxy[key] = (...args: any[]) => (ls[key] as (...args: any[]) => any)(...args); continue; } const memo = Utils.memoize( - (_version: number, _active: string, _caret: number, _selectEnd: number, _marker: string | undefined, ...args: any[]) => (ls[key] as Function)(...args), + (_version: number, _active: string, _caret: number, _selectEnd: number, _marker: string | undefined, ...args: any[]) => (ls[key] as (...args: any[]) => any)(...args), (...args) => args.map(a => a && typeof a === "object" ? JSON.stringify(a) : a).join("|,|") ); proxy[key] = (...args: any[]) => memo( From c7a8baeb14f23efcb9fdbc2c3c867a7d4e691593 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:31:31 -0700 Subject: [PATCH 2/2] Add comment pointing to Symbol issue --- .eslintrc.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 3e172986d22e8..2bd9211a3d923 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -84,7 +84,9 @@ { "extendDefaults": true, "types": { - "Symbol": false, // This is theoretically good, but ts-eslint appears to mistake our declaration of Symbol for the global Symbol type. + // This is theoretically good, but ts-eslint appears to mistake our declaration of Symbol for the global Symbol type. + // See: https://github.com/typescript-eslint/typescript-eslint/issues/7306 + "Symbol": false, "{}": false // {} is a totally useful and valid type. } }