Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use ts-expect-error instead of ts-ignore #6876

Merged
merged 3 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions std/node/_util/_util_promisify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export function promisify(original: Function): Function {
throw new NodeInvalidArgTypeError("original", "Function", original);
}

// @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
if (original[kCustomPromisifiedSymbol]) {
// @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 fn = original[kCustomPromisifiedSymbol];
if (typeof fn !== "function") {
throw new NodeInvalidArgTypeError(
Expand All @@ -82,20 +82,20 @@ export function promisify(original: Function): Function {

// Names to create an object from in case the callback receives multiple
// arguments, e.g. ['bytesRead', 'buffer'] for fs.read.
// @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 argumentNames = original[kCustomPromisifyArgsSymbol];

function fn(...args: unknown[]): Promise<unknown> {
return new Promise((resolve, reject) => {
// @ts-ignore: 'this' implicitly has type 'any' because it does not have a type annotation
// @ts-expect-error: 'this' implicitly has type 'any' because it does not have a type annotation
original.call(this, ...args, (err: Error, ...values: unknown[]) => {
if (err) {
return reject(err);
}
if (argumentNames !== undefined && values.length > 1) {
const obj = {};
for (let i = 0; i < argumentNames.length; i++) {
// @ts-ignore TypeScript
// @ts-expect-error TypeScript
obj[argumentNames[i]] = values[i];
}
resolve(obj);
Expand Down
12 changes: 6 additions & 6 deletions std/node/_util/_util_promisify_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Deno.test("Promisify.custom", async function testPromisifyCustom() {
function fn(): void {}

function promisifedFn(): void {}
// @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
fn[promisify.custom] = promisifedFn;

const promisifiedFnA = promisify(fn);
Expand All @@ -63,7 +63,7 @@ Deno.test("promiisfy.custom symbol", function testPromisifyCustomSymbol() {
// util.promisify.custom is a shared symbol which can be accessed
// as `Symbol.for("nodejs.util.promisify.custom")`.
const kCustomPromisifiedSymbol = Symbol.for("nodejs.util.promisify.custom");
// @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
fn[kCustomPromisifiedSymbol] = promisifiedFn;

assertStrictEquals(kCustomPromisifiedSymbol, promisify.custom);
Expand All @@ -73,7 +73,7 @@ Deno.test("promiisfy.custom symbol", function testPromisifyCustomSymbol() {

Deno.test("Invalid argument should throw", function testThrowInvalidArgument() {
function fn(): void {}
// @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
fn[promisify.custom] = 42;
try {
promisify(fn);
Expand All @@ -91,7 +91,7 @@ Deno.test("Custom promisify args", async function testPromisifyCustomArgs() {
callback(null, firstValue, secondValue);
}

// @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
fn[customPromisifyArgs] = ["first", "second"];

const obj = await promisify(fn)();
Expand Down Expand Up @@ -159,7 +159,7 @@ Deno.test(
Deno.test("Rejected value", async function testPromisifyWithAsObjectMethod() {
const o: { fn?: Function } = {};
const fn = promisify(function (cb: Function): void {
// @ts-ignore TypeScript
// @ts-expect-error TypeScript
cb(null, this === o);
});

Expand Down Expand Up @@ -220,7 +220,7 @@ Deno.test("Test error", async function testInvalidArguments() {
Deno.test("Test invalid arguments", function testInvalidArguments() {
[undefined, null, true, 0, "str", {}, [], Symbol()].forEach((input) => {
try {
// @ts-ignore TypeScript
// @ts-expect-error TypeScript
promisify(input);
} catch (e) {
assertStrictEquals(e.code, "ERR_INVALID_ARG_TYPE");
Expand Down
20 changes: 6 additions & 14 deletions std/node/buffer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Deno.test({
name: "Buffer global scope",
fn() {
// deno-lint-ignore ban-ts-comment
// @ts-ignore
// @ts-expect-error
assert(window.Buffer === Buffer);
// deno-lint-ignore ban-ts-comment
// @ts-ignore
// @ts-expect-error
assert(globalThis.Buffer === Buffer);
},
});
Expand Down Expand Up @@ -36,7 +36,7 @@ Deno.test({
assertThrows(
() => {
// deno-lint-ignore ban-ts-comment
// @ts-ignore
// @ts-expect-error
Buffer.alloc(size);
},
TypeError,
Expand All @@ -55,8 +55,6 @@ Deno.test({
for (const value of invalidValues) {
assertThrows(
() => {
// deno-lint-ignore ban-ts-comment
// @ts-ignore
console.log(value.constructor.name);
Buffer.alloc(1, value);
},
Expand Down Expand Up @@ -399,7 +397,7 @@ Deno.test({
assertThrows(
() => {
// deno-lint-ignore ban-ts-comment
// @ts-ignore
// @ts-expect-error
buffer.toString(encoding);
},
TypeError,
Expand All @@ -418,15 +416,13 @@ Deno.test({

for (const encoding of defaultToUtf8Encodings) {
// deno-lint-ignore ban-ts-comment
// @ts-ignore
// @ts-expect-error
assertEquals(Buffer.from("yes", encoding).toString(), "yes");
}

for (const encoding of invalidEncodings) {
assertThrows(
() => {
// deno-lint-ignore ban-ts-comment
// @ts-ignore
Buffer.from("yes", encoding);
},
TypeError,
Expand All @@ -445,8 +441,6 @@ Deno.test({
for (const encoding of notImplemented) {
assertThrows(
() => {
// deno-lint-ignore ban-ts-comment
// @ts-ignore
buffer.toString(encoding);
},
Error,
Expand All @@ -456,8 +450,6 @@ Deno.test({

assertThrows(
() => {
// deno-lint-ignore ban-ts-comment
// @ts-ignore
Buffer.from("", encoding);
},
Error,
Expand Down Expand Up @@ -586,7 +578,7 @@ Deno.test({

assertThrows(
// deno-lint-ignore ban-ts-comment
// @ts-ignore
// @ts-expect-error
() => Buffer.alloc(1).equals("abc"),
TypeError,
`The "otherBuffer" argument must be an instance of Buffer or Uint8Array. Received type string`,
Expand Down