Skip to content

Commit

Permalink
fix: Better use of @ts-expect-error (denoland/deno#6038)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk authored and caspervonb committed Jan 31, 2021
1 parent 370e9e4 commit 7c261e9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions mime/multipart_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ test("multipartMultipartWriter3", async function (): Promise<void> {
);
await assertThrowsAsync(
async (): Promise<void> => {
// @ts-expect-error
await mw.writeFile("bar", "file", null);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await mw.writeFile("bar", "file", null as any);
},
Error,
"closed"
Expand Down
4 changes: 2 additions & 2 deletions node/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Object.defineProperty(globalThis, Symbol.toStringTag, {
configurable: true,
});

// @ts-expect-error
globalThis["global"] = globalThis;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any)["global"] = globalThis;
24 changes: 10 additions & 14 deletions node/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,11 @@ class Module {
if (requireStack.length > 0) {
message = message + "\nRequire stack:\n- " + requireStack.join("\n- ");
}
const err = new Error(message);
// @ts-expect-error
const err = new Error(message) as Error & {
code: string;
requireStack: string[];
};
err.code = "MODULE_NOT_FOUND";
// @ts-expect-error
err.requireStack = requireStack;
throw err;
}
Expand Down Expand Up @@ -732,12 +733,10 @@ function tryPackage(
if (actual === false) {
actual = tryExtensions(path.resolve(requestPath, "index"), exts, isMain);
if (!actual) {
// eslint-disable-next-line no-restricted-syntax
const err = new Error(
`Cannot find module '${filename}'. ` +
'Please verify that the package.json has a valid "main" entry'
);
// @ts-expect-error
) as Error & { code: string };
err.code = "MODULE_NOT_FOUND";
throw err;
}
Expand Down Expand Up @@ -881,8 +880,7 @@ function applyExports(basePath: string, expansion: string): string {
const e = new Error(
`Package exports for '${basePath}' do not define ` +
`a '${mappingKey}' subpath`
);
// @ts-expect-error
) as Error & { code?: string };
e.code = "MODULE_NOT_FOUND";
throw e;
}
Expand Down Expand Up @@ -973,7 +971,7 @@ function resolveExportsTarget(
}
}
}
let e: Error;
let e: Error & { code?: string };
if (mappingKey !== ".") {
e = new Error(
`Package exports for '${basePath}' do not define a ` +
Expand All @@ -982,7 +980,6 @@ function resolveExportsTarget(
} else {
e = new Error(`No valid exports main found for '${basePath}'`);
}
// @ts-expect-error
e.code = "MODULE_NOT_FOUND";
throw e;
}
Expand All @@ -1006,8 +1003,7 @@ const CircularRequirePrototypeWarningProxy = new Proxy(
{},
{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get(target, prop): any {
// @ts-expect-error
get(target: Record<string, any>, prop: string): any {
if (prop in target) return target[prop];
emitCircularRequireWarning(prop);
return undefined;
Expand Down Expand Up @@ -1058,8 +1054,8 @@ type RequireWrapper = (
function wrapSafe(filename: string, content: string): RequireWrapper {
// TODO: fix this
const wrapper = Module.wrap(content);
// @ts-expect-error
const [f, err] = Deno.core.evalContext(wrapper, filename);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [f, err] = (Deno as any).core.evalContext(wrapper, filename);
if (err) {
throw err;
}
Expand Down
4 changes: 2 additions & 2 deletions signal/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ test({
fn() {
assertThrows(
() => {
// @ts-expect-error
signal();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(signal as any)();
},
Error,
"No signals are given. You need to specify at least one signal to create a signal stream."
Expand Down
2 changes: 1 addition & 1 deletion ws/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export async function handshake(
throw new Error("ws: invalid status line: " + statusLine);
}

// @ts-expect-error
assert(m.groups);
const { version, statusCode } = m.groups;
if (version !== "HTTP/1.1" || statusCode !== "101") {
throw new Error(
Expand Down

0 comments on commit 7c261e9

Please sign in to comment.