diff options
author | Maximilien Mellen <maxmellen0@gmail.com> | 2020-02-19 21:36:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 15:36:18 -0500 |
commit | 90125566bbaed8b5c6e55ca8dbc432e3433fb73c (patch) | |
tree | bf798a408b26264641260395ce8cfc9d4bb37637 /cli/js | |
parent | 852823fa505d75d61e70e1330bbf366aa248e650 (diff) |
Enable TS strict mode by default (#3899)
Fixes #3324
Co-authored-by: Kitson Kelly <me@kitsonkelly.com>
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/body_test.ts | 6 | ||||
-rw-r--r-- | cli/js/buffer_test.ts | 20 | ||||
-rw-r--r-- | cli/js/chmod_test.ts | 10 | ||||
-rw-r--r-- | cli/js/compiler_host.ts | 3 | ||||
-rw-r--r-- | cli/js/console_test.ts | 7 | ||||
-rw-r--r-- | cli/js/error_stack_test.ts | 4 | ||||
-rw-r--r-- | cli/js/event_target_test.ts | 22 | ||||
-rw-r--r-- | cli/js/event_test.ts | 13 | ||||
-rw-r--r-- | cli/js/fetch_test.ts | 22 | ||||
-rw-r--r-- | cli/js/file_test.ts | 6 | ||||
-rw-r--r-- | cli/js/files_test.ts | 2 | ||||
-rw-r--r-- | cli/js/form_data_test.ts | 17 | ||||
-rw-r--r-- | cli/js/headers_test.ts | 16 | ||||
-rw-r--r-- | cli/js/internals_test.ts | 4 | ||||
-rw-r--r-- | cli/js/mixins/dom_iterable_test.ts | 16 | ||||
-rw-r--r-- | cli/js/net_test.ts | 2 | ||||
-rw-r--r-- | cli/js/os_test.ts | 6 | ||||
-rw-r--r-- | cli/js/process_test.ts | 17 | ||||
-rw-r--r-- | cli/js/resources_test.ts | 4 | ||||
-rw-r--r-- | cli/js/signal_test.ts | 2 | ||||
-rw-r--r-- | cli/js/stat_test.ts | 2 | ||||
-rw-r--r-- | cli/js/test_util.ts | 11 | ||||
-rw-r--r-- | cli/js/timers_test.ts | 17 | ||||
-rw-r--r-- | cli/js/tls_test.ts | 2 | ||||
-rw-r--r-- | cli/js/url_search_params_test.ts | 3 | ||||
-rw-r--r-- | cli/js/utime_test.ts | 4 | ||||
-rw-r--r-- | cli/js/write_file_test.ts | 8 |
27 files changed, 162 insertions, 84 deletions
diff --git a/cli/js/body_test.ts b/cli/js/body_test.ts index 2ac4d1314..d7f5c6d61 100644 --- a/cli/js/body_test.ts +++ b/cli/js/body_test.ts @@ -45,7 +45,7 @@ testPerm({ net: true }, async function bodyMultipartFormData(): Promise<void> { const formData = await body.formData(); assert(formData.has("field_1")); - assertEquals(formData.get("field_1").toString(), "value_1 \r\n"); + assertEquals(formData.get("field_1")!.toString(), "value_1 \r\n"); assert(formData.has("field_2")); }); @@ -62,7 +62,7 @@ testPerm({ net: true }, async function bodyURLEncodedFormData(): Promise<void> { const formData = await body.formData(); assert(formData.has("field_1")); - assertEquals(formData.get("field_1").toString(), "Hi"); + assertEquals(formData.get("field_1")!.toString(), "Hi"); assert(formData.has("field_2")); - assertEquals(formData.get("field_2").toString(), "<Deno>"); + assertEquals(formData.get("field_2")!.toString(), "<Deno>"); }); diff --git a/cli/js/buffer_test.ts b/cli/js/buffer_test.ts index 4b5701e54..72c0cab4b 100644 --- a/cli/js/buffer_test.ts +++ b/cli/js/buffer_test.ts @@ -3,7 +3,7 @@ // This code has been ported almost directly from Go's src/bytes/buffer_test.go // Copyright 2009 The Go Authors. All rights reserved. BSD license. // https://github.com/golang/go/blob/master/LICENSE -import { assertEquals, test } from "./test_util.ts"; +import { assert, assertEquals, test } from "./test_util.ts"; const { Buffer, readAll, readAllSync, writeAll, writeAllSync } = Deno; type Buffer = Deno.Buffer; @@ -78,12 +78,16 @@ function repeat(c: string, bytes: number): Uint8Array { test(function bufferNewBuffer(): void { init(); + assert(testBytes); + assert(testString); const buf = new Buffer(testBytes.buffer as ArrayBuffer); check(buf, testString); }); test(async function bufferBasicOperations(): Promise<void> { init(); + assert(testBytes); + assert(testString); const buf = new Buffer(); for (let i = 0; i < 5; i++) { check(buf, ""); @@ -134,8 +138,8 @@ test(async function bufferLargeByteWrites(): Promise<void> { const buf = new Buffer(); const limit = 9; for (let i = 3; i < limit; i += 3) { - const s = await fillBytes(buf, "", 5, testBytes); - await empty(buf, s, new Uint8Array(Math.floor(testString.length / i))); + const s = await fillBytes(buf, "", 5, testBytes!); + await empty(buf, s, new Uint8Array(Math.floor(testString!.length / i))); } check(buf, ""); }); @@ -161,6 +165,8 @@ test(async function bufferTooLargeByteWrites(): Promise<void> { test(async function bufferLargeByteReads(): Promise<void> { init(); + assert(testBytes); + assert(testString); const buf = new Buffer(); for (let i = 3; i < 30; i += 3) { const n = Math.floor(testBytes.byteLength / i); @@ -177,6 +183,8 @@ test(function bufferCapWithPreallocatedSlice(): void { test(async function bufferReadFrom(): Promise<void> { init(); + assert(testBytes); + assert(testString); const buf = new Buffer(); for (let i = 3; i < 30; i += 3) { const s = await fillBytes( @@ -194,6 +202,8 @@ test(async function bufferReadFrom(): Promise<void> { test(async function bufferReadFromSync(): Promise<void> { init(); + assert(testBytes); + assert(testString); const buf = new Buffer(); for (let i = 3; i < 30; i += 3) { const s = await fillBytes( @@ -236,6 +246,7 @@ test(async function bufferTestGrow(): Promise<void> { test(async function testReadAll(): Promise<void> { init(); + assert(testBytes); const reader = new Buffer(testBytes.buffer as ArrayBuffer); const actualBytes = await readAll(reader); assertEquals(testBytes.byteLength, actualBytes.byteLength); @@ -246,6 +257,7 @@ test(async function testReadAll(): Promise<void> { test(function testReadAllSync(): void { init(); + assert(testBytes); const reader = new Buffer(testBytes.buffer as ArrayBuffer); const actualBytes = readAllSync(reader); assertEquals(testBytes.byteLength, actualBytes.byteLength); @@ -256,6 +268,7 @@ test(function testReadAllSync(): void { test(async function testWriteAll(): Promise<void> { init(); + assert(testBytes); const writer = new Buffer(); await writeAll(writer, testBytes); const actualBytes = writer.bytes(); @@ -267,6 +280,7 @@ test(async function testWriteAll(): Promise<void> { test(function testWriteAllSync(): void { init(); + assert(testBytes); const writer = new Buffer(); writeAllSync(writer, testBytes); const actualBytes = writer.bytes(); diff --git a/cli/js/chmod_test.ts b/cli/js/chmod_test.ts index 3ecb4256a..b3b0a2ae2 100644 --- a/cli/js/chmod_test.ts +++ b/cli/js/chmod_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { testPerm, assertEquals } from "./test_util.ts"; +import { testPerm, assert, assertEquals } from "./test_util.ts"; const isNotWindows = Deno.build.os !== "win"; @@ -16,6 +16,7 @@ testPerm({ read: true, write: true }, function chmodSyncSuccess(): void { // Check success when not on windows if (isNotWindows) { const fileInfo = Deno.statSync(filename); + assert(fileInfo.mode); assertEquals(fileInfo.mode & 0o777, 0o777); } }); @@ -35,14 +36,17 @@ if (isNotWindows) { Deno.symlinkSync(filename, symlinkName); let symlinkInfo = Deno.lstatSync(symlinkName); + assert(symlinkInfo.mode); const symlinkMode = symlinkInfo.mode & 0o777; // platform dependent Deno.chmodSync(symlinkName, 0o777); // Change actual file mode, not symlink const fileInfo = Deno.statSync(filename); + assert(fileInfo.mode); assertEquals(fileInfo.mode & 0o777, 0o777); symlinkInfo = Deno.lstatSync(symlinkName); + assert(symlinkInfo.mode); assertEquals(symlinkInfo.mode & 0o777, symlinkMode); } ); @@ -86,6 +90,7 @@ testPerm({ read: true, write: true }, async function chmodSuccess(): Promise< // Check success when not on windows if (isNotWindows) { const fileInfo = Deno.statSync(filename); + assert(fileInfo.mode); assertEquals(fileInfo.mode & 0o777, 0o777); } }); @@ -105,14 +110,17 @@ if (isNotWindows) { Deno.symlinkSync(filename, symlinkName); let symlinkInfo = Deno.lstatSync(symlinkName); + assert(symlinkInfo.mode); const symlinkMode = symlinkInfo.mode & 0o777; // platform dependent await Deno.chmod(symlinkName, 0o777); // Just change actual file mode, not symlink const fileInfo = Deno.statSync(filename); + assert(fileInfo.mode); assertEquals(fileInfo.mode & 0o777, 0o777); symlinkInfo = Deno.lstatSync(symlinkName); + assert(symlinkInfo.mode); assertEquals(symlinkInfo.mode & 0o777, symlinkMode); } ); diff --git a/cli/js/compiler_host.ts b/cli/js/compiler_host.ts index 8f19eb326..d44bc7a03 100644 --- a/cli/js/compiler_host.ts +++ b/cli/js/compiler_host.ts @@ -49,8 +49,7 @@ export const defaultBundlerOptions: ts.CompilerOptions = { export const defaultCompileOptions: ts.CompilerOptions = { allowJs: true, allowNonTsExtensions: true, - // TODO(#3324) Enable strict mode for user code. - // strict: true, + strict: true, checkJs: false, esModuleInterop: true, module: ts.ModuleKind.ESNext, diff --git a/cli/js/console_test.ts b/cli/js/console_test.ts index b80dd8284..d9492cf2d 100644 --- a/cli/js/console_test.ts +++ b/cli/js/console_test.ts @@ -14,8 +14,8 @@ const customInspect = Deno.symbols.customInspect; const { Console, stringifyArgs - // eslint-disable-next-line @typescript-eslint/no-explicit-any -} = Deno[Deno.symbols.internal] as any; + // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol +} = Deno[Deno.symbols.internal]; function stringify(...args: unknown[]): string { return stringifyArgs(args).replace(/\n$/, ""); @@ -306,6 +306,7 @@ test(function consoleTestCallToStringOnLabel(): void { for (const method of methods) { let hasCalled = false; + // @ts-ignore console[method]({ toString(): void { hasCalled = true; @@ -451,6 +452,7 @@ test(function consoleGroup(): void { // console.group with console.warn test test(function consoleGroupWarn(): void { mockConsole((console, _out, _err, both): void => { + assert(both); console.warn("1"); console.group(); console.warn("2"); @@ -694,6 +696,7 @@ test(function consoleDirXml(): void { test(function consoleTrace(): void { mockConsole((console, _out, err): void => { console.trace("%s", "custom message"); + assert(err); assert(err.toString().includes("Trace: custom message")); }); }); diff --git a/cli/js/error_stack_test.ts b/cli/js/error_stack_test.ts index e4e44c77f..12755c166 100644 --- a/cli/js/error_stack_test.ts +++ b/cli/js/error_stack_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { test, assert } from "./test_util.ts"; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const { setPrepareStackTrace } = Deno[Deno.symbols.internal] as any; +// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol +const { setPrepareStackTrace } = Deno[Deno.symbols.internal]; interface CallSite { getThis(): unknown; diff --git a/cli/js/event_target_test.ts b/cli/js/event_target_test.ts index aead97ed3..34d42d014 100644 --- a/cli/js/event_target_test.ts +++ b/cli/js/event_target_test.ts @@ -4,8 +4,11 @@ import { test, assertEquals } from "./test_util.ts"; test(function addEventListenerTest(): void { const document = new EventTarget(); + // @ts-ignore tests ignoring the type system for resilience assertEquals(document.addEventListener("x", null, false), undefined); + // @ts-ignore assertEquals(document.addEventListener("x", null, true), undefined); + // @ts-ignore assertEquals(document.addEventListener("x", null), undefined); }); @@ -14,7 +17,7 @@ test(function constructedEventTargetCanBeUsedAsExpected(): void { const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; - const listener = (e): void => { + const listener = (e: Event): void => { assertEquals(e, event); ++callCount; }; @@ -34,11 +37,19 @@ test(function constructedEventTargetCanBeUsedAsExpected(): void { test(function anEventTargetCanBeSubclassed(): void { class NicerEventTarget extends EventTarget { - on(type, callback?, options?): void { + on( + type: string, + callback: (e: Event) => void | null, + options?: __domTypes.AddEventListenerOptions + ): void { this.addEventListener(type, callback, options); } - off(type, callback?, options?): void { + off( + type: string, + callback: (e: Event) => void | null, + options?: __domTypes.EventListenerOptions + ): void { this.removeEventListener(type, callback, options); } } @@ -60,8 +71,11 @@ test(function anEventTargetCanBeSubclassed(): void { test(function removingNullEventListenerShouldSucceed(): void { const document = new EventTarget(); + // @ts-ignore assertEquals(document.removeEventListener("x", null, false), undefined); + // @ts-ignore assertEquals(document.removeEventListener("x", null, true), undefined); + // @ts-ignore assertEquals(document.removeEventListener("x", null), undefined); }); @@ -70,7 +84,7 @@ test(function constructedEventTargetUseObjectPrototype(): void { const event = new Event("toString", { bubbles: true, cancelable: false }); let callCount = 0; - const listener = (e): void => { + const listener = (e: Event): void => { assertEquals(e, event); ++callCount; }; diff --git a/cli/js/event_test.ts b/cli/js/event_test.ts index affd979ee..2ff23daf9 100644 --- a/cli/js/event_test.ts +++ b/cli/js/event_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test, assertEquals, assertNotEquals } from "./test_util.ts"; +import { test, assertEquals, assert } from "./test_util.ts"; test(function eventInitializedWithType(): void { const type = "click"; @@ -70,7 +70,8 @@ test(function eventPreventDefaultSuccess(): void { }); test(function eventInitializedWithNonStringType(): void { - const type = undefined; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const type: any = undefined; const event = new Event(type); assertEquals(event.isTrusted, false); @@ -84,12 +85,12 @@ test(function eventInitializedWithNonStringType(): void { // ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js test(function eventIsTrusted(): void { const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted"); - assertNotEquals(desc1, undefined); + assert(desc1); assertEquals(typeof desc1.get, "function"); const desc2 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted"); - assertNotEquals(desc2, undefined); - assertEquals(typeof desc2.get, "function"); + assert(desc2); + assertEquals(typeof desc2!.get, "function"); - assertEquals(desc1.get, desc2.get); + assertEquals(desc1!.get, desc2!.get); }); diff --git a/cli/js/fetch_test.ts b/cli/js/fetch_test.ts index 2b3d03a38..c63d05501 100644 --- a/cli/js/fetch_test.ts +++ b/cli/js/fetch_test.ts @@ -54,7 +54,7 @@ testPerm({ net: true }, async function fetchHeaders(): Promise<void> { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); const headers = response.headers; assertEquals(headers.get("Content-Type"), "application/json"); - assert(headers.get("Server").startsWith("SimpleHTTP")); + assert(headers.get("Server")!.startsWith("SimpleHTTP")); }); testPerm({ net: true }, async function fetchBlob(): Promise<void> { @@ -93,10 +93,10 @@ testPerm({ net: true }, async function responseClone(): Promise<void> { assert(response !== response1); assertEquals(response.status, response1.status); assertEquals(response.statusText, response1.statusText); - const ab = await response.arrayBuffer(); - const ab1 = await response1.arrayBuffer(); - for (let i = 0; i < ab.byteLength; i++) { - assertEquals(ab[i], ab1[i]); + const u8a = new Uint8Array(await response.arrayBuffer()); + const u8a1 = new Uint8Array(await response1.arrayBuffer()); + for (let i = 0; i < u8a.byteLength; i++) { + assertEquals(u8a[i], u8a1[i]); } }); @@ -119,7 +119,7 @@ testPerm({ net: true }, async function fetchMultipartFormDataSuccess(): Promise< ); const formData = await response.formData(); assert(formData.has("field_1")); - assertEquals(formData.get("field_1").toString(), "value_1 \r\n"); + assertEquals(formData.get("field_1")!.toString(), "value_1 \r\n"); assert(formData.has("field_2")); /* TODO(ry) Re-enable this test once we bring back the global File type. const file = formData.get("field_2") as File; @@ -136,9 +136,9 @@ testPerm( ); const formData = await response.formData(); assert(formData.has("field_1")); - assertEquals(formData.get("field_1").toString(), "Hi"); + assertEquals(formData.get("field_1")!.toString(), "Hi"); assert(formData.has("field_2")); - assertEquals(formData.get("field_2").toString(), "<Deno>"); + assertEquals(formData.get("field_2")!.toString(), "<Deno>"); } ); @@ -179,7 +179,7 @@ testPerm({ net: true }, async function fetchInitStringBody(): Promise<void> { }); const text = await response.text(); assertEquals(text, data); - assert(response.headers.get("content-type").startsWith("text/plain")); + assert(response.headers.get("content-type")!.startsWith("text/plain")); }); testPerm({ net: true }, async function fetchRequestInitStringBody(): Promise< @@ -220,7 +220,7 @@ testPerm({ net: true }, async function fetchInitURLSearchParamsBody(): Promise< assertEquals(text, data); assert( response.headers - .get("content-type") + .get("content-type")! .startsWith("application/x-www-form-urlencoded") ); }); @@ -236,7 +236,7 @@ testPerm({ net: true }, async function fetchInitBlobBody(): Promise<void> { }); const text = await response.text(); assertEquals(text, data); - assert(response.headers.get("content-type").startsWith("text/javascript")); + assert(response.headers.get("content-type")!.startsWith("text/javascript")); }); testPerm({ net: true }, async function fetchUserAgent(): Promise<void> { diff --git a/cli/js/file_test.ts b/cli/js/file_test.ts index 2d009c0c2..8fc37f701 100644 --- a/cli/js/file_test.ts +++ b/cli/js/file_test.ts @@ -1,7 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { test, assert, assertEquals } from "./test_util.ts"; -function testFirstArgument(arg1, expectedSize): void { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function testFirstArgument(arg1: any[], expectedSize: number): void { const file = new File(arg1, "name"); assert(file instanceof File); assertEquals(file.name, "name"); @@ -76,7 +77,8 @@ test(function fileObjectInFileBits(): void { testFirstArgument([{}], 15); }); -function testSecondArgument(arg2, expectedFileName): void { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function testSecondArgument(arg2: any, expectedFileName: string): void { const file = new File(["bits"], arg2); assert(file instanceof File); assertEquals(file.name, expectedFileName); diff --git a/cli/js/files_test.ts b/cli/js/files_test.ts index 8f4beb085..03e4d00e9 100644 --- a/cli/js/files_test.ts +++ b/cli/js/files_test.ts @@ -157,6 +157,7 @@ testPerm({ write: true }, async function writeNullBufferFailure(): Promise< // writing null should throw an error let err; try { + // @ts-ignore await file.write(null); } catch (e) { err = e; @@ -182,6 +183,7 @@ testPerm( // reading file into null buffer should throw an error let err; try { + // @ts-ignore await file.read(null); } catch (e) { err = e; diff --git a/cli/js/form_data_test.ts b/cli/js/form_data_test.ts index a40326fba..10147d8b9 100644 --- a/cli/js/form_data_test.ts +++ b/cli/js/form_data_test.ts @@ -36,7 +36,9 @@ test(function formDataParamsGetSuccess(): void { formData.append("a", "true"); formData.append("b", "false"); formData.append("a", "null"); + // @ts-ignore formData.append("d", undefined); + // @ts-ignore formData.append("e", null); assertEquals(formData.get("a"), "true"); assertEquals(formData.get("b"), "false"); @@ -63,8 +65,10 @@ test(function formDataParamsSetSuccess(): void { assertEquals(formData.getAll("b"), ["false"]); formData.set("a", "false"); assertEquals(formData.getAll("a"), ["false"]); + // @ts-ignore formData.set("d", undefined); assertEquals(formData.get("d"), "undefined"); + // @ts-ignore formData.set("e", null); assertEquals(formData.get("e"), "null"); }); @@ -101,15 +105,22 @@ test(function formDataParamsForEachSuccess(): void { }); test(function formDataParamsArgumentsCheck(): void { - const methodRequireOneParam = ["delete", "getAll", "get", "has", "forEach"]; + const methodRequireOneParam = [ + "delete", + "getAll", + "get", + "has", + "forEach" + ] as const; - const methodRequireTwoParams = ["append", "set"]; + const methodRequireTwoParams = ["append", "set"] as const; methodRequireOneParam.forEach((method): void => { const formData = new FormData(); let hasThrown = 0; let errMsg = ""; try { + // @ts-ignore formData[method](); hasThrown = 1; } catch (err) { @@ -133,6 +144,7 @@ test(function formDataParamsArgumentsCheck(): void { let errMsg = ""; try { + // @ts-ignore formData[method](); hasThrown = 1; } catch (err) { @@ -152,6 +164,7 @@ test(function formDataParamsArgumentsCheck(): void { hasThrown = 0; errMsg = ""; try { + // @ts-ignore formData[method]("foo"); hasThrown = 1; } catch (err) { diff --git a/cli/js/headers_test.ts b/cli/js/headers_test.ts index 15e1191f5..65e04ada3 100644 --- a/cli/js/headers_test.ts +++ b/cli/js/headers_test.ts @@ -2,8 +2,8 @@ import { test, assert, assertEquals } from "./test_util.ts"; const { stringifyArgs - // eslint-disable-next-line @typescript-eslint/no-explicit-any -} = Deno[Deno.symbols.internal] as any; + // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol +} = Deno[Deno.symbols.internal]; // Logic heavily copied from web-platform-tests, make // sure pass mostly header basic test @@ -13,6 +13,7 @@ test(function newHeaderTest(): void { new Headers(undefined); new Headers({}); try { + // @ts-ignore new Headers(null); } catch (e) { assertEquals( @@ -22,14 +23,16 @@ test(function newHeaderTest(): void { } }); -const headerDict = { +const headerDict: Record<string, string> = { name1: "value1", name2: "value2", name3: "value3", + // @ts-ignore name4: undefined, "Content-Type": "value4" }; -const headerSeq = []; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const headerSeq: any[] = []; for (const name in headerDict) { headerSeq.push([name, headerDict[name]]); } @@ -133,7 +136,7 @@ test(function headerValuesSuccess(): void { } }); -const headerEntriesDict = { +const headerEntriesDict: Record<string, string> = { name1: "value1", Name2: "value2", name: "value3", @@ -261,6 +264,7 @@ test(function headerParamsArgumentsCheck(): void { let hasThrown = 0; let errMsg = ""; try { + // @ts-ignore headers[method](); hasThrown = 1; } catch (err) { @@ -284,6 +288,7 @@ test(function headerParamsArgumentsCheck(): void { let errMsg = ""; try { + // @ts-ignore headers[method](); hasThrown = 1; } catch (err) { @@ -303,6 +308,7 @@ test(function headerParamsArgumentsCheck(): void { hasThrown = 0; errMsg = ""; try { + // @ts-ignore headers[method]("foo"); hasThrown = 1; } catch (err) { diff --git a/cli/js/internals_test.ts b/cli/js/internals_test.ts index 055995fdf..47aea09e7 100644 --- a/cli/js/internals_test.ts +++ b/cli/js/internals_test.ts @@ -4,7 +4,7 @@ import { test, assert } from "./test_util.ts"; test(function internalsExists(): void { const { stringifyArgs - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } = Deno[Deno.symbols.internal] as any; + // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol + } = Deno[Deno.symbols.internal]; assert(!!stringifyArgs); }); diff --git a/cli/js/mixins/dom_iterable_test.ts b/cli/js/mixins/dom_iterable_test.ts index 466375d64..5dc45dc20 100644 --- a/cli/js/mixins/dom_iterable_test.ts +++ b/cli/js/mixins/dom_iterable_test.ts @@ -20,11 +20,8 @@ function setup() { Base, // This is using an internal API we don't want published as types, so having // to cast to any to "trick" TypeScript - // eslint-disable-next-line @typescript-eslint/no-explicit-any - DomIterable: (Deno[Deno.symbols.internal] as any).DomIterableMixin( - Base, - dataSymbol - ) + // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol + DomIterable: Deno[Deno.symbols.internal].DomIterableMixin(Base, dataSymbol) }; } @@ -52,7 +49,12 @@ test(function testDomIterable(): void { result = []; const scope = {}; - function callback(value, key, parent): void { + function callback( + this: typeof scope, + value: number, + key: string, + parent: typeof domIterable + ): void { assertEquals(parent, domIterable); assert(key != null); assert(value != null); @@ -72,7 +74,7 @@ test(function testDomIterableScope(): void { // eslint-disable-next-line @typescript-eslint/no-explicit-any function checkScope(thisArg: any, expected: any): void { - function callback(): void { + function callback(this: typeof thisArg): void { assertEquals(this, expected); } domIterable.forEach(callback, thisArg); diff --git a/cli/js/net_test.ts b/cli/js/net_test.ts index e4d0be81f..68b1918b9 100644 --- a/cli/js/net_test.ts +++ b/cli/js/net_test.ts @@ -27,7 +27,7 @@ testPerm({ net: true }, async function netCloseWhileAccept(): Promise<void> { testPerm({ net: true }, async function netConcurrentAccept(): Promise<void> { const listener = Deno.listen({ port: 4502 }); let acceptErrCount = 0; - const checkErr = (e): void => { + const checkErr = (e: Deno.DenoError<Deno.ErrorKind>): void => { assertEquals(e.kind, Deno.ErrorKind.Other); if (e.message === "Listener has been closed") { assertEquals(acceptErrCount, 1); diff --git a/cli/js/os_test.ts b/cli/js/os_test.ts index 6d9309000..a461ba63e 100644 --- a/cli/js/os_test.ts +++ b/cli/js/os_test.ts @@ -56,7 +56,10 @@ if (Deno.build.os === "win") { // specified in `inputEnv`. The subprocess reads the environment variables // which are in the keys of `expectedEnv` and writes them to stdout as JSON. // It is then verified that these match with the values of `expectedEnv`. - const checkChildEnv = async (inputEnv, expectedEnv): Promise<void> => { + const checkChildEnv = async ( + inputEnv: Record<string, string>, + expectedEnv: Record<string, string> + ): Promise<void> => { const src = ` console.log( ${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env(k)) @@ -249,6 +252,7 @@ testPerm({ env: true }, function getDir(): void { if (Deno.build.os !== r.os) continue; if (r.shouldHaveValue) { const d = Deno.dir(s.kind); + assert(d); assert(d.length > 0); } } diff --git a/cli/js/process_test.ts b/cli/js/process_test.ts index 943359e54..dce4d9918 100644 --- a/cli/js/process_test.ts +++ b/cli/js/process_test.ts @@ -130,6 +130,7 @@ testPerm({ run: true }, async function runStdinPiped(): Promise<void> { args: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"], stdin: "piped" }); + assert(p.stdin); assert(!p.stdout); assert(!p.stderr); @@ -137,7 +138,7 @@ testPerm({ run: true }, async function runStdinPiped(): Promise<void> { const n = await p.stdin.write(msg); assertEquals(n, msg.byteLength); - p.stdin.close(); + p.stdin!.close(); const status = await p.status(); assertEquals(status.success, true); @@ -155,16 +156,16 @@ testPerm({ run: true }, async function runStdoutPiped(): Promise<void> { assert(!p.stderr); const data = new Uint8Array(10); - let r = await p.stdout.read(data); + let r = await p.stdout!.read(data); if (r === Deno.EOF) { throw new Error("p.stdout.read(...) should not be EOF"); } assertEquals(r, 5); const s = new TextDecoder().decode(data.subarray(0, r)); assertEquals(s, "hello"); - r = await p.stdout.read(data); + r = await p.stdout!.read(data); assertEquals(r, Deno.EOF); - p.stdout.close(); + p.stdout!.close(); const status = await p.status(); assertEquals(status.success, true); @@ -182,16 +183,16 @@ testPerm({ run: true }, async function runStderrPiped(): Promise<void> { assert(!p.stdout); const data = new Uint8Array(10); - let r = await p.stderr.read(data); + let r = await p.stderr!.read(data); if (r === Deno.EOF) { throw new Error("p.stderr.read should not return EOF here"); } assertEquals(r, 5); const s = new TextDecoder().decode(data.subarray(0, r)); assertEquals(s, "hello"); - r = await p.stderr.read(data); + r = await p.stderr!.read(data); assertEquals(r, Deno.EOF); - p.stderr.close(); + p.stderr!.close(); const status = await p.status(); assertEquals(status.success, true); @@ -307,7 +308,7 @@ testPerm({ run: true }, async function runClose(): Promise<void> { p.close(); const data = new Uint8Array(10); - const r = await p.stderr.read(data); + const r = await p.stderr!.read(data); assertEquals(r, Deno.EOF); }); diff --git a/cli/js/resources_test.ts b/cli/js/resources_test.ts index 367b66217..5d1e27af7 100644 --- a/cli/js/resources_test.ts +++ b/cli/js/resources_test.ts @@ -39,8 +39,8 @@ testPerm({ read: true }, async function resourcesFile(): Promise<void> { Object.keys(resourcesAfter).length, Object.keys(resourcesBefore).length + 1 ); - const newRid = Object.keys(resourcesAfter).find((rid): boolean => { + const newRid = +Object.keys(resourcesAfter).find((rid): boolean => { return !resourcesBefore.hasOwnProperty(rid); - }); + })!; assertEquals(resourcesAfter[newRid], "fsFile"); }); diff --git a/cli/js/signal_test.ts b/cli/js/signal_test.ts index 06457314c..1c8658477 100644 --- a/cli/js/signal_test.ts +++ b/cli/js/signal_test.ts @@ -8,7 +8,7 @@ import { } from "./test_util.ts"; function defer(n: number): Promise<void> { - return new Promise((resolve, _) => { + return new Promise((resolve: () => void, _) => { setTimeout(resolve, n); }); } diff --git a/cli/js/stat_test.ts b/cli/js/stat_test.ts index 9b03c0ece..bce5449ac 100644 --- a/cli/js/stat_test.ts +++ b/cli/js/stat_test.ts @@ -210,7 +210,7 @@ if (isWindows) { const s = Deno.statSync(filename); assert(s.dev !== null); assert(s.ino !== null); - assertEquals(s.mode & 0o666, 0o666); + assertEquals(s.mode! & 0o666, 0o666); assertEquals(s.nlink, 2); assert(s.uid !== null); assert(s.gid !== null); diff --git a/cli/js/test_util.ts b/cli/js/test_util.ts index dbb7bf2c4..3e089486b 100644 --- a/cli/js/test_util.ts +++ b/cli/js/test_util.ts @@ -62,7 +62,10 @@ function permissionsMatch( requiredPerms: Permissions ): boolean { for (const permName in processPerms) { - if (processPerms[permName] !== requiredPerms[permName]) { + if ( + processPerms[permName as keyof Permissions] !== + requiredPerms[permName as keyof Permissions] + ) { return false; } } @@ -302,7 +305,7 @@ testPerm( async function assertAllUnitTestFilesImported(): Promise<void> { const directoryTestFiles = Deno.readDirSync("./cli/js") .map(k => k.name) - .filter(file => file.endsWith("_test.ts")); + .filter(file => file!.endsWith("_test.ts")); const unitTestsFile: Uint8Array = Deno.readFileSync( "./cli/js/unit_tests.ts" ); @@ -311,11 +314,11 @@ testPerm( .split("\n") .filter(line => line.startsWith("import") && line.includes("_test.ts")); const importedTestFiles = importLines.map( - relativeFilePath => relativeFilePath.match(/\/([^\/]+)";/)[1] + relativeFilePath => relativeFilePath.match(/\/([^\/]+)";/)![1] ); directoryTestFiles.forEach(dirFile => { - if (!importedTestFiles.includes(dirFile)) { + if (!importedTestFiles.includes(dirFile!)) { throw new Error( "cil/js/unit_tests.ts is missing import of test file: cli/js/" + dirFile diff --git a/cli/js/timers_test.ts b/cli/js/timers_test.ts index b71df9254..84811ff11 100644 --- a/cli/js/timers_test.ts +++ b/cli/js/timers_test.ts @@ -7,21 +7,22 @@ function deferred(): { // eslint-disable-next-line @typescript-eslint/no-explicit-any reject: (reason?: any) => void; } { - let resolve; - let reject; - const promise = new Promise((res, rej): void => { + let resolve: (value?: {} | PromiseLike<{}>) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let reject: ((reason?: any) => void) | undefined = undefined; + const promise = new Promise<{}>((res, rej): void => { resolve = res; reject = rej; }); return { promise, - resolve, - reject + resolve: resolve!, + reject: reject! }; } -async function waitForMs(ms): Promise<number> { - return new Promise((resolve): number => setTimeout(resolve, ms)); +async function waitForMs(ms: number): Promise<number> { + return new Promise((resolve: () => void): number => setTimeout(resolve, ms)); } test(async function timeoutSuccess(): Promise<void> { @@ -133,7 +134,7 @@ test(async function intervalCancelSuccess(): Promise<void> { }); test(async function intervalOrdering(): Promise<void> { - const timers = []; + const timers: number[] = []; let timeouts = 0; function onTimeout(): void { ++timeouts; diff --git a/cli/js/tls_test.ts b/cli/js/tls_test.ts index 1273da34f..ac59a2eb9 100644 --- a/cli/js/tls_test.ts +++ b/cli/js/tls_test.ts @@ -195,7 +195,7 @@ testPerm({ read: true, net: true }, async function dialAndListenTLS(): Promise< assertEquals(ok, "OK"); const headers = await tpr.readMIMEHeader(); assert(headers !== Deno.EOF); - const contentLength = parseInt(headers.get("content-length")); + const contentLength = parseInt(headers.get("content-length")!); const bodyBuf = new Uint8Array(contentLength); await r.readFull(bodyBuf); assertEquals(decoder.decode(bodyBuf), "Hello World\n"); diff --git a/cli/js/url_search_params_test.ts b/cli/js/url_search_params_test.ts index c1343e59b..8619568bd 100644 --- a/cli/js/url_search_params_test.ts +++ b/cli/js/url_search_params_test.ts @@ -177,6 +177,7 @@ test(function urlSearchParamsAppendArgumentsCheck(): void { const searchParams = new URLSearchParams(); let hasThrown = 0; try { + // @ts-ignore searchParams[method](); hasThrown = 1; } catch (err) { @@ -193,6 +194,7 @@ test(function urlSearchParamsAppendArgumentsCheck(): void { const searchParams = new URLSearchParams(); let hasThrown = 0; try { + // @ts-ignore searchParams[method]("foo"); hasThrown = 1; } catch (err) { @@ -232,6 +234,7 @@ test(function urlSearchParamsCustomSymbolIterator(): void { test(function urlSearchParamsCustomSymbolIteratorWithNonStringParams(): void { const params = {}; + // @ts-ignore params[Symbol.iterator] = function*(): IterableIterator<[number, number]> { yield [1, 2]; }; diff --git a/cli/js/utime_test.ts b/cli/js/utime_test.ts index 15c218df4..72a4a6477 100644 --- a/cli/js/utime_test.ts +++ b/cli/js/utime_test.ts @@ -3,7 +3,9 @@ import { testPerm, assert, assertEquals } from "./test_util.ts"; // Allow 10 second difference. // Note this might not be enough for FAT (but we are not testing on such fs). -function assertFuzzyTimestampEquals(t1: number, t2: number): void { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function assertFuzzyTimestampEquals(t1: any, t2: number): void { + assert(typeof t1 === "number"); assert(Math.abs(t1 - t2) < 10); } diff --git a/cli/js/write_file_test.ts b/cli/js/write_file_test.ts index 30500b594..2b952655f 100644 --- a/cli/js/write_file_test.ts +++ b/cli/js/write_file_test.ts @@ -50,9 +50,9 @@ testPerm({ read: true, write: true }, function writeFileSyncUpdatePerm(): void { const data = enc.encode("Hello"); const filename = Deno.makeTempDirSync() + "/test.txt"; Deno.writeFileSync(filename, data, { perm: 0o755 }); - assertEquals(Deno.statSync(filename).mode & 0o777, 0o755); + assertEquals(Deno.statSync(filename).mode! & 0o777, 0o755); Deno.writeFileSync(filename, data, { perm: 0o666 }); - assertEquals(Deno.statSync(filename).mode & 0o777, 0o666); + assertEquals(Deno.statSync(filename).mode! & 0o777, 0o666); } }); @@ -161,9 +161,9 @@ testPerm( const data = enc.encode("Hello"); const filename = Deno.makeTempDirSync() + "/test.txt"; await Deno.writeFile(filename, data, { perm: 0o755 }); - assertEquals(Deno.statSync(filename).mode & 0o777, 0o755); + assertEquals(Deno.statSync(filename).mode! & 0o777, 0o755); await Deno.writeFile(filename, data, { perm: 0o666 }); - assertEquals(Deno.statSync(filename).mode & 0o777, 0o666); + assertEquals(Deno.statSync(filename).mode! & 0o777, 0o666); } } ); |