mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
fix: Better use of @ts-expect-error (#6038)
This commit is contained in:
parent
8b1b4766a1
commit
3fe6bc1b82
24 changed files with 152 additions and 145 deletions
|
@ -214,7 +214,13 @@ function evaluateCallSite(callSite: CallSite): CallSiteEval {
|
|||
};
|
||||
}
|
||||
|
||||
function prepareStackTrace(error: Error, callSites: CallSite[]): string {
|
||||
function prepareStackTrace(
|
||||
error: Error & {
|
||||
__callSiteEvals: CallSiteEval[];
|
||||
__formattedFrames: string[];
|
||||
},
|
||||
callSites: CallSite[]
|
||||
): string {
|
||||
const mappedCallSites = callSites.map(
|
||||
(callSite): CallSite => {
|
||||
const fileName = callSite.getFileName();
|
||||
|
@ -238,19 +244,14 @@ function prepareStackTrace(error: Error, callSites: CallSite[]): string {
|
|||
__formattedFrames: { value: [], configurable: true },
|
||||
});
|
||||
for (const callSite of mappedCallSites) {
|
||||
// @ts-expect-error
|
||||
error.__callSiteEvals.push(Object.freeze(evaluateCallSite(callSite)));
|
||||
const isInternal = callSite.getFileName()?.startsWith("$deno$") ?? false;
|
||||
// @ts-expect-error
|
||||
error.__formattedFrames.push(callSiteToString(callSite, isInternal));
|
||||
}
|
||||
// @ts-expect-error
|
||||
Object.freeze(error.__callSiteEvals);
|
||||
// @ts-expect-error
|
||||
Object.freeze(error.__formattedFrames);
|
||||
return (
|
||||
`${error.name}: ${error.message}\n` +
|
||||
// @ts-expect-error
|
||||
error.__formattedFrames
|
||||
.map((s: string) => ` at ${colors.stripColor(s)}`)
|
||||
.join("\n")
|
||||
|
|
|
@ -35,8 +35,8 @@ 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-expect-error
|
||||
return globalThis.closed;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return (globalThis as any).closed;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
|
|
@ -30,8 +30,8 @@ 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-expect-error
|
||||
denoNs[internalSymbol] = internalObject;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(denoNs as any)[internalSymbol] = internalObject;
|
||||
|
||||
let windowIsClosing = false;
|
||||
|
||||
|
@ -71,8 +71,8 @@ export function bootstrapMainRuntime(): void {
|
|||
throw new Error("Worker runtime already bootstrapped");
|
||||
}
|
||||
// Remove bootstrapping methods from global scope
|
||||
// @ts-expect-error
|
||||
globalThis.bootstrap = undefined;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(globalThis as any).bootstrap = undefined;
|
||||
log("bootstrapMainRuntime");
|
||||
hasBootstrapped = true;
|
||||
Object.defineProperties(globalThis, windowOrWorkerGlobalScopeMethods);
|
||||
|
|
|
@ -33,8 +33,8 @@ 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-expect-error
|
||||
denoNs[internalSymbol] = internalObject;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(denoNs as any)[internalSymbol] = internalObject;
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
|
@ -128,8 +128,8 @@ export function bootstrapWorkerRuntime(
|
|||
throw new Error("Worker runtime already bootstrapped");
|
||||
}
|
||||
// Remove bootstrapping methods from global scope
|
||||
// @ts-expect-error
|
||||
globalThis.bootstrap = undefined;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(globalThis as any).bootstrap = undefined;
|
||||
log("bootstrapWorkerRuntime");
|
||||
hasBootstrapped = true;
|
||||
Object.defineProperties(globalThis, windowOrWorkerGlobalScopeMethods);
|
||||
|
|
|
@ -336,8 +336,8 @@ async function runTests({
|
|||
const originalConsole = globalThis.console;
|
||||
|
||||
if (disableLog) {
|
||||
// @ts-expect-error
|
||||
globalThis.console = disabledConsole;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(globalThis as any).console = disabledConsole;
|
||||
}
|
||||
|
||||
let endMsg: TestMessage["end"];
|
||||
|
|
|
@ -216,14 +216,18 @@ function groupEntries<T>(
|
|||
lineMaxLength += separatorSpace;
|
||||
maxLineLength[i] = lineMaxLength;
|
||||
}
|
||||
let order = "padStart";
|
||||
let order: "padStart" | "padEnd" = "padStart";
|
||||
if (value !== undefined) {
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
//@ts-expect-error
|
||||
if (typeof value[i] !== "number" && typeof value[i] !== "bigint") {
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
if (
|
||||
typeof (value as any)[i] !== "number" &&
|
||||
typeof (value as any)[i] !== "bigint"
|
||||
) {
|
||||
order = "padEnd";
|
||||
break;
|
||||
}
|
||||
/* eslint-enable */
|
||||
}
|
||||
}
|
||||
// Each iteration creates a single line of grouped entries.
|
||||
|
@ -235,7 +239,6 @@ function groupEntries<T>(
|
|||
for (; j < max - 1; j++) {
|
||||
// In future, colors should be taken here into the account
|
||||
const padding = maxLineLength[j - i];
|
||||
//@ts-expect-error
|
||||
str += `${entries[j]}, `[order](padding, " ");
|
||||
}
|
||||
if (order === "padStart") {
|
||||
|
@ -408,8 +411,8 @@ function createMapString(
|
|||
},
|
||||
group: false,
|
||||
};
|
||||
//@ts-expect-error
|
||||
return createIterableString(value, ctx, level, maxLevel, printConfig);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return createIterableString(value as any, ctx, level, maxLevel, printConfig);
|
||||
}
|
||||
|
||||
function createWeakSetString(): string {
|
||||
|
@ -477,7 +480,7 @@ function createPromiseString(
|
|||
// TODO: Proxy
|
||||
|
||||
function createRawObjectString(
|
||||
value: { [key: string]: unknown },
|
||||
value: Record<string, unknown>,
|
||||
ctx: ConsoleContext,
|
||||
level: number,
|
||||
maxLevel: number
|
||||
|
@ -490,8 +493,9 @@ function createRawObjectString(
|
|||
let baseString = "";
|
||||
|
||||
let shouldShowDisplayName = false;
|
||||
// @ts-expect-error
|
||||
let displayName = value[Symbol.toStringTag];
|
||||
let displayName = (value as { [Symbol.toStringTag]: string })[
|
||||
Symbol.toStringTag
|
||||
];
|
||||
if (!displayName) {
|
||||
displayName = getClassInstanceName(value);
|
||||
}
|
||||
|
@ -511,8 +515,8 @@ function createRawObjectString(
|
|||
for (const key of symbolKeys) {
|
||||
entries.push(
|
||||
`${key.toString()}: ${stringifyWithQuotes(
|
||||
// @ts-expect-error
|
||||
value[key],
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
value[key as any],
|
||||
ctx,
|
||||
level + 1,
|
||||
maxLevel
|
||||
|
|
|
@ -187,7 +187,7 @@ function sendFetchReq(
|
|||
}
|
||||
|
||||
export async function fetch(
|
||||
input: domTypes.Request | URL | string,
|
||||
input: (domTypes.Request & { _bodySource?: unknown }) | URL | string,
|
||||
init?: domTypes.RequestInit
|
||||
): Promise<Response> {
|
||||
let url: string;
|
||||
|
@ -285,7 +285,6 @@ export async function fetch(
|
|||
method = input.method;
|
||||
headers = input.headers;
|
||||
|
||||
//@ts-expect-error
|
||||
if (input._bodySource) {
|
||||
body = new DataView(await input.arrayBuffer());
|
||||
}
|
||||
|
|
|
@ -234,23 +234,23 @@ function setTimer(
|
|||
}
|
||||
|
||||
export function setTimeout(
|
||||
this: unknown,
|
||||
cb: (...args: Args) => void,
|
||||
delay = 0,
|
||||
...args: Args
|
||||
): number {
|
||||
checkBigInt(delay);
|
||||
// @ts-expect-error
|
||||
checkThis(this);
|
||||
return setTimer(cb, delay, args, false);
|
||||
}
|
||||
|
||||
export function setInterval(
|
||||
this: unknown,
|
||||
cb: (...args: Args) => void,
|
||||
delay = 0,
|
||||
...args: Args
|
||||
): number {
|
||||
checkBigInt(delay);
|
||||
// @ts-expect-error
|
||||
checkThis(this);
|
||||
return setTimer(cb, delay, args, true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue