1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-08 15:19:40 -05:00

Use ts-expect-error instead of ts-ignore. (#5869)

This commit is contained in:
Kitson Kelly 2020-05-27 00:02:16 +10:00 committed by GitHub
parent 24c36fd862
commit 228f9c207f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 81 additions and 94 deletions

View file

@ -244,19 +244,19 @@ function prepareStackTrace(
}
)
.map((callSite): string => {
// @ts-ignore
// @ts-expect-error
error.__callSiteEvals.push(Object.freeze(evaluateCallSite(callSite)));
const isInternal =
callSite.getFileName()?.startsWith("$deno$") ?? false;
const string = callSiteToString(callSite, isInternal);
// @ts-ignore
// @ts-expect-error
error.__formattedFrames.push(string);
return ` at ${colors.stripColor(string)}`;
})
.join("\n");
// @ts-ignore
// @ts-expect-error
Object.freeze(error.__callSiteEvals);
// @ts-ignore
// @ts-expect-error
Object.freeze(error.__formattedFrames);
return errorString;
}

View file

@ -35,7 +35,7 @@ function isRecoverableError(e: Error): boolean {
// Returns `true` if `close()` is called in REPL.
// We should quit the REPL when this function returns `true`.
function isCloseCalled(): boolean {
// @ts-ignore
// @ts-expect-error
return globalThis.closed;
}

View file

@ -30,7 +30,7 @@ import { log, immutableDefine } from "./util.ts";
// TODO: factor out `Deno` global assignment to separate function
// Add internal object to Deno object.
// This is not exposed as part of the Deno types.
// @ts-ignore
// @ts-expect-error
denoNs[internalSymbol] = internalObject;
let windowIsClosing = false;
@ -71,7 +71,7 @@ export function bootstrapMainRuntime(): void {
throw new Error("Worker runtime already bootstrapped");
}
// Remove bootstrapping methods from global scope
// @ts-ignore
// @ts-expect-error
globalThis.bootstrap = undefined;
log("bootstrapMainRuntime");
hasBootstrapped = true;

View file

@ -33,7 +33,7 @@ import { setSignals } from "./signals.ts";
// TODO: factor out `Deno` global assignment to separate function
// Add internal object to Deno object.
// This is not exposed as part of the Deno types.
// @ts-ignore
// @ts-expect-error
denoNs[internalSymbol] = internalObject;
const encoder = new TextEncoder();
@ -128,7 +128,7 @@ export function bootstrapWorkerRuntime(
throw new Error("Worker runtime already bootstrapped");
}
// Remove bootstrapping methods from global scope
// @ts-ignore
// @ts-expect-error
globalThis.bootstrap = undefined;
log("bootstrapWorkerRuntime");
hasBootstrapped = true;

View file

@ -333,11 +333,10 @@ async function runTests({
const filterFn = createFilterFn(filter, skip);
const testApi = new TestApi(TEST_REGISTRY, filterFn, failFast);
// @ts-ignore
const originalConsole = globalThis.console;
if (disableLog) {
// @ts-ignore
// @ts-expect-error
globalThis.console = disabledConsole;
}
@ -356,7 +355,6 @@ async function runTests({
}
if (disableLog) {
// @ts-ignore
globalThis.console = originalConsole;
}

View file

@ -100,7 +100,6 @@ export class Body implements domTypes.Body {
}
if (this._bodySource instanceof ReadableStreamImpl) {
// @ts-ignore
this._stream = this._bodySource;
}
if (typeof this._bodySource === "string") {
@ -290,7 +289,6 @@ export class Body implements domTypes.Body {
enc.encode(this._bodySource).buffer as ArrayBuffer
);
} else if (this._bodySource instanceof ReadableStreamImpl) {
// @ts-ignore
return bufferFromStream(this._bodySource.getReader());
} else if (this._bodySource instanceof FormData) {
const enc = new TextEncoder();

View file

@ -223,7 +223,7 @@ function groupEntries<T>(
let order = "padStart";
if (value !== undefined) {
for (let i = 0; i < entries.length; i++) {
//@ts-ignore
//@ts-expect-error
if (typeof value[i] !== "number" && typeof value[i] !== "bigint") {
order = "padEnd";
break;
@ -239,7 +239,7 @@ function groupEntries<T>(
for (; j < max - 1; j++) {
// In future, colors should be taken here into the account
const padding = maxLineLength[j - i];
//@ts-ignore
//@ts-expect-error
str += `${entries[j]}, `[order](padding, " ");
}
if (order === "padStart") {
@ -412,7 +412,7 @@ function createMapString(
},
group: false,
};
//@ts-ignore
//@ts-expect-error
return createIterableString(value, ctx, level, maxLevel, printConfig);
}
@ -494,7 +494,7 @@ function createRawObjectString(
let baseString = "";
let shouldShowDisplayName = false;
// @ts-ignore
// @ts-expect-error
let displayName = value[Symbol.toStringTag];
if (!displayName) {
displayName = getClassInstanceName(value);
@ -515,7 +515,7 @@ function createRawObjectString(
for (const key of symbolKeys) {
entries.push(
`${key.toString()}: ${stringifyWithQuotes(
// @ts-ignore
// @ts-expect-error
value[key],
ctx,
level + 1,
@ -949,7 +949,7 @@ export class Console {
name: "Trace",
message,
};
// @ts-ignore
// @ts-expect-error
Error.captureStackTrace(err, this.trace);
this.error((err as Error).stack);
};

View file

@ -282,7 +282,7 @@ export async function fetch(
method = input.method;
headers = input.headers;
//@ts-ignore
//@ts-expect-error
if (input._bodySource) {
body = new DataView(await input.arrayBuffer());
}

View file

@ -239,7 +239,7 @@ export function setTimeout(
...args: Args
): number {
checkBigInt(delay);
// @ts-ignore
// @ts-expect-error
checkThis(this);
return setTimer(cb, delay, args, false);
}
@ -250,7 +250,7 @@ export function setInterval(
...args: Args
): number {
checkBigInt(delay);
// @ts-ignore
// @ts-expect-error
checkThis(this);
return setTimer(cb, delay, args, true);
}

View file

@ -1,4 +1,4 @@
// @ts-ignore
// @ts-expect-error
Deno.core.evalContext(
"(async () => console.log(await import('./subdir/mod4.js')))()"
);

View file

@ -42,7 +42,7 @@ unitTest(
const body = buildBody(text);
// @ts-ignore
// @ts-expect-error
body.contentType = "multipart/form-data;boundary=boundary";
const formData = await body.formData();
@ -62,7 +62,7 @@ unitTest(
const body = buildBody(text);
// @ts-ignore
// @ts-expect-error
body.contentType = "application/x-www-form-urlencoded";
const formData = await body.formData();

View file

@ -22,7 +22,7 @@ const customInspect = Deno.customInspect;
const {
Console,
stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.internal];
function stringify(...args: unknown[]): string {
@ -590,7 +590,7 @@ unitTest(function consoleTestStringifyIterable() {
0, <120 empty items>
]`
);
*/
*/
});
unitTest(async function consoleTestStringifyPromises(): Promise<void> {
@ -727,7 +727,6 @@ unitTest(function consoleTestCallToStringOnLabel(): void {
mockConsole((console) => {
for (const method of methods) {
let hasCalled = false;
// @ts-ignore
console[method]({
toString(): void {
hasCalled = true;

View file

@ -20,9 +20,9 @@ unitTest(
);
unitTest(function malformedJsonControlBuffer(): void {
// @ts-ignore
// @ts-expect-error
const opId = Deno.core.ops()["op_open"];
// @ts-ignore
// @ts-expect-error
const res = Deno.core.send(opId, new Uint8Array([1, 2, 3, 4, 5]));
const resText = new TextDecoder().decode(res);
// eslint-disable-next-line @typescript-eslint/no-explicit-any

View file

@ -26,9 +26,9 @@ unitTest(async function sendAsyncStackTrace(): Promise<void> {
});
unitTest(function malformedMinimalControlBuffer(): void {
// @ts-ignore
// @ts-expect-error
const readOpId = Deno.core.ops()["op_read"];
// @ts-ignore
// @ts-expect-error
const res = Deno.core.send(readOpId, new Uint8Array([1, 2, 3, 4, 5]));
const header = res.slice(0, 12);
const buf32 = new Int32Array(

View file

@ -20,7 +20,7 @@ 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
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
DomIterable: Deno[Deno.internal].DomIterableMixin(Base, dataSymbol),
};
}

View file

@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { unitTest, assert } from "./test_util.ts";
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
const { setPrepareStackTrace } = Deno[Deno.internal];
interface CallSite {

View file

@ -4,11 +4,8 @@ import { unitTest, assertEquals } from "./test_util.ts";
unitTest(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);
});
@ -71,11 +68,8 @@ unitTest(function anEventTargetCanBeSubclassed(): void {
unitTest(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);
});

View file

@ -93,7 +93,7 @@ unitTest({ perms: { net: true } }, async function fetchBodyUsed(): Promise<
assertEquals(response.bodyUsed, false);
assertThrows((): void => {
// Assigning to read-only property throws in the strict mode.
// @ts-ignore
// @ts-expect-error
response.bodyUsed = true;
});
await response.blob();
@ -595,7 +595,7 @@ unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise<
const methods = ["json", "text", "formData", "arrayBuffer"];
for (const method of methods) {
try {
// @ts-ignore
// @ts-expect-error
await response[method]();
fail(
"Reading body multiple times should failed, the stream should've been locked."

View file

@ -290,7 +290,7 @@ unitTest(
// writing null should throw an error
let err;
try {
// @ts-ignore
// @ts-expect-error
await file.write(null);
} catch (e) {
err = e;
@ -322,7 +322,7 @@ unitTest(
// reading file into null buffer should throw an error
let err;
try {
// @ts-ignore
// @ts-expect-error
await file.read(null);
} catch (e) {
err = e;

View file

@ -41,9 +41,9 @@ unitTest(function formDataParamsGetSuccess(): void {
formData.append("a", "true");
formData.append("b", "false");
formData.append("a", "null");
// @ts-ignore
// @ts-expect-error
formData.append("d", undefined);
// @ts-ignore
// @ts-expect-error
formData.append("e", null);
assertEquals(formData.get("a"), "true");
assertEquals(formData.get("b"), "false");
@ -70,10 +70,10 @@ unitTest(function formDataParamsSetSuccess(): void {
assertEquals(formData.getAll("b"), ["false"]);
formData.set("a", "false");
assertEquals(formData.getAll("a"), ["false"]);
// @ts-ignore
// @ts-expect-error
formData.set("d", undefined);
assertEquals(formData.get("d"), "undefined");
// @ts-ignore
// @ts-expect-error
formData.set("e", null);
assertEquals(formData.get("e"), "null");
});
@ -134,7 +134,7 @@ unitTest(function formDataParamsArgumentsCheck(): void {
let hasThrown = 0;
let errMsg = "";
try {
// @ts-ignore
// @ts-expect-error
formData[method]();
hasThrown = 1;
} catch (err) {
@ -158,7 +158,7 @@ unitTest(function formDataParamsArgumentsCheck(): void {
let errMsg = "";
try {
// @ts-ignore
// @ts-expect-error
formData[method]();
hasThrown = 1;
} catch (err) {
@ -178,7 +178,7 @@ unitTest(function formDataParamsArgumentsCheck(): void {
hasThrown = 0;
errMsg = "";
try {
// @ts-ignore
// @ts-expect-error
formData[method]("foo");
hasThrown = 1;
} catch (err) {

View file

@ -48,12 +48,12 @@ unitTest(function webAssemblyExists(): void {
unitTest(function DenoNamespaceImmutable(): void {
const denoCopy = window.Deno;
try {
// @ts-ignore
// @ts-expect-error
Deno = 1;
} catch {}
assert(denoCopy === Deno);
try {
// @ts-ignore
// @ts-expect-error
window.Deno = 1;
} catch {}
assert(denoCopy === Deno);
@ -64,7 +64,7 @@ unitTest(function DenoNamespaceImmutable(): void {
const { readFile } = Deno;
try {
// @ts-ignore
// @ts-expect-error
Deno.readFile = 1;
} catch {}
assert(readFile === Deno.readFile);
@ -73,19 +73,19 @@ unitTest(function DenoNamespaceImmutable(): void {
} catch {}
assert(readFile === Deno.readFile);
// @ts-ignore
// @ts-expect-error
const { print } = Deno.core;
try {
// @ts-ignore
// @ts-expect-error
Deno.core.print = 1;
} catch {}
// @ts-ignore
// @ts-expect-error
assert(print === Deno.core.print);
try {
// @ts-ignore
// @ts-expect-error
delete Deno.core.print;
} catch {}
// @ts-ignore
// @ts-expect-error
assert(print === Deno.core.print);
});

View file

@ -7,7 +7,7 @@ import {
} from "./test_util.ts";
const {
stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.internal];
// Logic heavily copied from web-platform-tests, make
@ -18,7 +18,7 @@ unitTest(function newHeaderTest(): void {
new Headers(undefined);
new Headers({});
try {
// @ts-ignore
// @ts-expect-error
new Headers(null);
} catch (e) {
assertEquals(
@ -32,7 +32,7 @@ const headerDict: Record<string, string> = {
name1: "value1",
name2: "value2",
name3: "value3",
// @ts-ignore
// @ts-expect-error
name4: undefined,
"Content-Type": "value4",
};
@ -269,7 +269,7 @@ unitTest(function headerParamsArgumentsCheck(): void {
let hasThrown = 0;
let errMsg = "";
try {
// @ts-ignore
// @ts-expect-error
headers[method]();
hasThrown = 1;
} catch (err) {
@ -293,7 +293,7 @@ unitTest(function headerParamsArgumentsCheck(): void {
let errMsg = "";
try {
// @ts-ignore
// @ts-expect-error
headers[method]();
hasThrown = 1;
} catch (err) {
@ -313,7 +313,7 @@ unitTest(function headerParamsArgumentsCheck(): void {
hasThrown = 0;
errMsg = "";
try {
// @ts-ignore
// @ts-expect-error
headers[method]("foo");
hasThrown = 1;
} catch (err) {

View file

@ -4,7 +4,7 @@ import { unitTest, assert } from "./test_util.ts";
unitTest(function internalsExists(): void {
const {
stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.internal];
assert(!!stringifyArgs);
});

View file

@ -10,7 +10,7 @@ unitTest(function fromInit(): void {
},
});
// @ts-ignore
// @ts-expect-error
assertEquals("ahoyhoy", req._bodySource);
assertEquals(req.url, "https://example.com");
assertEquals(req.headers.get("test-header"), "value");
@ -18,13 +18,13 @@ unitTest(function fromInit(): void {
unitTest(function fromRequest(): void {
const r = new Request("https://example.com");
// @ts-ignore
// @ts-expect-error
r._bodySource = "ahoyhoy";
r.headers.set("test-header", "value");
const req = new Request(r);
// @ts-ignore
// @ts-expect-error
assertEquals(req._bodySource, r._bodySource);
assertEquals(req.url, r.url);
assertEquals(req.headers.get("test-header"), r.headers.get("test-header"));
@ -44,6 +44,6 @@ unitTest(async function cloneRequestBodyStream(): Promise<void> {
assertEquals(b1, b2);
// @ts-ignore
// @ts-expect-error
assert(r1._bodySource !== r2._bodySource);
});

View file

@ -8,7 +8,7 @@ unitTest(function streamReadableHwmError() {
() => {
new ReadableStream<number>(
undefined,
// @ts-ignore
// @ts-expect-error
{ highWaterMark }
);
},
@ -20,7 +20,7 @@ unitTest(function streamReadableHwmError() {
assertThrows(() => {
new ReadableStream<number>(
undefined,
// @ts-ignore
// @ts-expect-error
{ highWaterMark: Symbol("hwk") }
);
}, TypeError);
@ -33,7 +33,7 @@ unitTest(function streamWriteableHwmError() {
() => {
new WritableStream(
undefined,
// @ts-ignore
// @ts-expect-error
new CountQueuingStrategy({ highWaterMark })
);
},
@ -45,7 +45,7 @@ unitTest(function streamWriteableHwmError() {
assertThrows(() => {
new WritableStream(
undefined,
// @ts-ignore
// @ts-expect-error
new CountQueuingStrategy({ highWaterMark: Symbol("hwmk") })
);
}, TypeError);
@ -59,7 +59,7 @@ unitTest(function streamTransformHwmError() {
new TransformStream(
undefined,
undefined,
// @ts-ignore
// @ts-expect-error
{ highWaterMark }
);
},
@ -72,7 +72,7 @@ unitTest(function streamTransformHwmError() {
new TransformStream(
undefined,
undefined,
// @ts-ignore
// @ts-expect-error
{ highWaterMark: Symbol("hwmk") }
);
}, TypeError);

View file

@ -11,7 +11,7 @@ import {
reportToConn,
} from "./test_util.ts";
// @ts-ignore
// @ts-expect-error
const internalObj = Deno[Deno.internal];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const reportToConsole = internalObj.reportToConsole as (message: any) => void;

View file

@ -177,7 +177,7 @@ unitTest(function urlSearchParamsAppendArgumentsCheck(): void {
const searchParams = new URLSearchParams();
let hasThrown = 0;
try {
// @ts-ignore
// @ts-expect-error
searchParams[method]();
hasThrown = 1;
} catch (err) {
@ -194,7 +194,7 @@ unitTest(function urlSearchParamsAppendArgumentsCheck(): void {
const searchParams = new URLSearchParams();
let hasThrown = 0;
try {
// @ts-ignore
// @ts-expect-error
searchParams[method]("foo");
hasThrown = 1;
} catch (err) {
@ -235,7 +235,7 @@ unitTest(function urlSearchParamsCustomSymbolIterator(): void {
unitTest(
function urlSearchParamsCustomSymbolIteratorWithNonStringParams(): void {
const params = {};
// @ts-ignore
// @ts-expect-error
params[Symbol.iterator] = function* (): IterableIterator<[number, number]> {
yield [1, 2];
};

View file

@ -496,7 +496,6 @@ test({
async fn(): Promise<void> {
const serverRoutine = async (): Promise<void> => {
const server = serve(":8124");
// @ts-ignore
for await (const req of server) {
await assertThrowsAsync(async () => {
await req.respond({

View file

@ -145,7 +145,7 @@ test("multipartMultipartWriter3", async function (): Promise<void> {
);
await assertThrowsAsync(
async (): Promise<void> => {
// @ts-ignore
// @ts-expect-error
await mw.writeFile("bar", "file", null);
},
Error,

View file

@ -5,5 +5,5 @@ Object.defineProperty(globalThis, Symbol.toStringTag, {
configurable: true,
});
// @ts-ignore
// @ts-expect-error
globalThis["global"] = globalThis;

View file

@ -263,9 +263,9 @@ class Module {
message = message + "\nRequire stack:\n- " + requireStack.join("\n- ");
}
const err = new Error(message);
// @ts-ignore
// @ts-expect-error
err.code = "MODULE_NOT_FOUND";
// @ts-ignore
// @ts-expect-error
err.requireStack = requireStack;
throw err;
}
@ -737,7 +737,7 @@ function tryPackage(
`Cannot find module '${filename}'. ` +
'Please verify that the package.json has a valid "main" entry'
);
// @ts-ignore
// @ts-expect-error
err.code = "MODULE_NOT_FOUND";
throw err;
}
@ -882,7 +882,7 @@ function applyExports(basePath: string, expansion: string): string {
`Package exports for '${basePath}' do not define ` +
`a '${mappingKey}' subpath`
);
// @ts-ignore
// @ts-expect-error
e.code = "MODULE_NOT_FOUND";
throw e;
}
@ -982,7 +982,7 @@ function resolveExportsTarget(
} else {
e = new Error(`No valid exports main found for '${basePath}'`);
}
// @ts-ignore
// @ts-expect-error
e.code = "MODULE_NOT_FOUND";
throw e;
}
@ -1007,7 +1007,7 @@ const CircularRequirePrototypeWarningProxy = new Proxy(
{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get(target, prop): any {
// @ts-ignore
// @ts-expect-error
if (prop in target) return target[prop];
emitCircularRequireWarning(prop);
return undefined;
@ -1058,7 +1058,7 @@ type RequireWrapper = (
function wrapSafe(filename: string, content: string): RequireWrapper {
// TODO: fix this
const wrapper = Module.wrap(content);
// @ts-ignore
// @ts-expect-error
const [f, err] = Deno.core.evalContext(wrapper, filename);
if (err) {
throw err;

View file

@ -9,7 +9,7 @@ test({
fn() {
assertThrows(
() => {
// @ts-ignore
// @ts-expect-error
signal();
},
Error,

View file

@ -1,7 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assert } from "../../testing/asserts.ts";
const { test } = Deno;
// @ts-ignore
import { NIL_UUID, isNil } from "../mod.ts";
test({

View file

@ -491,7 +491,7 @@ export async function handshake(
throw new Error("ws: invalid status line: " + statusLine);
}
// @ts-ignore
// @ts-expect-error
const { version, statusCode } = m.groups;
if (version !== "HTTP/1.1" || statusCode !== "101") {
throw new Error(