Skip to content

Commit

Permalink
refactor: use tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Jan 21, 2025
1 parent 43540f3 commit 4b354dc
Show file tree
Hide file tree
Showing 31 changed files with 197 additions and 75 deletions.
2 changes: 1 addition & 1 deletion packages/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "A set of actions that we use for our workflows",
"private": true,
"scripts": {
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"build": "tsc --noEmit --lib ESNext,DOM && tsup",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
Expand Down
9 changes: 9 additions & 0 deletions packages/actions/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/brokers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"description": "Powerful set of message brokers",
"scripts": {
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"build": "tsc --noEmit --lib ESNext,DOM && tsup",
"build:docs": "tsc -p tsconfig.docs.json --lib ESNext,DOM",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
Expand Down
9 changes: 9 additions & 0 deletions packages/brokers/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.9.0",
"description": "A set of builders that you can use when creating your bot",
"scripts": {
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
Expand Down
9 changes: 9 additions & 0 deletions packages/builders/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "2.1.1",
"description": "Utility data structure used in discord.js",
"scripts": {
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
Expand Down
9 changes: 9 additions & 0 deletions packages/collection/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
109 changes: 59 additions & 50 deletions packages/core/__tests__/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
APIModalActionRowComponent,
RESTPostAPIInteractionCallbackWithResponseResult,
} from 'discord-api-types/v10';
import { assertType, describe, test } from 'vitest';
import { expectTypeOf, describe, test } from 'vitest';
import { API } from '../src/index.js';

const rest = new REST();
Expand All @@ -16,119 +16,128 @@ const boolValue = true as boolean;

describe('Interaction with_response overloads.', () => {
test('Replying returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: true }),
));
expectTypeOf(api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());

test('Replying returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.reply(SNOWFLAKE, TOKEN, {}));
assertType<Promise<undefined>>(api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: false }));
expectTypeOf(api.interactions.reply(SNOWFLAKE, TOKEN, {})).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});

test('Replying returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
expectTypeOf(api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: boolValue })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
>();
});

test('Defer returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: true }),
));
expectTypeOf(api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());

test('Defer returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.defer(SNOWFLAKE, TOKEN));
assertType<Promise<undefined>>(api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: false }));
expectTypeOf(api.interactions.defer(SNOWFLAKE, TOKEN)).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});

test('Defer returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
expectTypeOf(api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: boolValue })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
>();
});

test('Defer message update returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: true }),
));
expectTypeOf(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());

test('Defer message update returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN));
assertType<Promise<undefined>>(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: false }));
expectTypeOf(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN)).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});

test('Defer message update returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
expectTypeOf(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: boolValue })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
>();
});

test('Update message returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: true }),
));
expectTypeOf(api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());

test('Update message returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.updateMessage(SNOWFLAKE, TOKEN, {}));
assertType<Promise<undefined>>(api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: false }));
expectTypeOf(api.interactions.updateMessage(SNOWFLAKE, TOKEN, {})).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});

test('Update message returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
expectTypeOf(api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: boolValue })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
>();
});

test('Create autocomplete response returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: true }),
));
expectTypeOf(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());

test('Create autocomplete response returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, {}));
assertType<Promise<undefined>>(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: false }),
);
expectTypeOf(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, {})).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});

test('Create autocomplete response returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
expectTypeOf(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
).toEqualTypeOf<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>();
});

test('Create modal returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
expectTypeOf(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: true,
}),
));
).toEqualTypeOf<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>());

test('Create modal returns undefined.', () => {
assertType<Promise<undefined>>(
expectTypeOf(
api.interactions.createModal(SNOWFLAKE, TOKEN, { title: '', custom_id: '', components: MODAL_COMPONENTS }),
);
assertType<Promise<undefined>>(
).toEqualTypeOf<Promise<undefined>>();

expectTypeOf(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: false,
}),
);
).toEqualTypeOf<Promise<undefined>>();
});

test('Create modal returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
expectTypeOf(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: boolValue,
}),
);
).toEqualTypeOf<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>();
});
});
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "2.0.0",
"description": "A thinly abstracted wrapper around the rest API, and gateway.",
"scripts": {
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.cjs", "src/**/*.mjs", "bin", "__tests__", "../../vitest.d.ts"],
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.cjs", "src/**/*.mjs", "bin"],
"exclude": ["node_modules"]
}
9 changes: 9 additions & 0 deletions packages/core/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/formatters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.5.0",
"description": "A set of functions to format strings for Discord.",
"scripts": {
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
Expand Down
9 changes: 9 additions & 0 deletions packages/formatters/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.1.0",
"description": "A powerful TypeScript library for interacting with the Discord API",
"scripts": {
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
Expand Down
9 changes: 9 additions & 0 deletions packages/next/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "2.1.1",
"description": "Tools for running an HTTP proxy for Discord's API",
"scripts": {
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
Expand Down
9 changes: 9 additions & 0 deletions packages/proxy/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "2.4.0",
"description": "The REST API for discord.js",
"scripts": {
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
Expand Down
9 changes: 9 additions & 0 deletions packages/rest/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"test": "vitest run",
"test": "vitest run && tsc --project ./tsconfig.test.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
"fmt": "pnpm run format",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts", "../../vitest.d.ts"],
"exclude": ["node_modules"]
}
6 changes: 3 additions & 3 deletions packages/util/__tests__/types/Equatable.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expectType } from 'tsd';
import { expectTypeOf } from 'vitest';
import { isEquatable, type Equatable } from '../../src/index.js';

declare const unknownObj: unknown;

if (isEquatable(unknownObj)) {
expectType<Equatable<unknown>>(unknownObj);
expectType<boolean>(unknownObj.equals(unknownObj));
expectTypeOf(unknownObj).toEqualTypeOf<Equatable<unknown>>();
expectTypeOf(unknownObj.equals(unknownObj)).toEqualTypeOf<boolean>();
}
Loading

0 comments on commit 4b354dc

Please sign in to comment.