insyri / tpy

🔑 A strongly typed Pylon API client.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typing fixes

insyri opened this issue · comments

The cause comes from the way files are handled around Deno and Node.js. See affected lines:

import { RESTPostAPIGuildsJSONBody } from 'discord-api-types/rest/v8/guild.ts';
import { APIUnavailableGuild } from 'discord-api-types/payloads/v8/guild.ts';

In Deno, this is perfectly fine, in Node.js, the imports are not found. It would be required to instead reference the index of the v8 instead of the direct guild file, like so:

import { RESTPostAPIGuildsJSONBody } from "discord-api-types/rest/v8";
import { APIUnavailableGuild } from "discord-api-types/payloads/v8";

Inspect both of these inside an IDE and intellisense will prove it so. Also, Deno has the mod.ts extension rather than the index.ts, so we would have to add a script to edit that.

Pseudo Solution

The transpiled (deno->node, not ts->js) Node version of these imports look like this:

import { RESTPostAPIGuildsJSONBody } from "discord-api-types/rest/v8/guild";
import { APIUnavailableGuild } from "discord-api-types/payloads/v8/guild";

The directive to transform this would be to reference the parent folder of the guild module.

- import { RESTPostAPIGuildsJSONBody } from "discord-api-types/rest/v8/guild";
+ import { RESTPostAPIGuildsJSONBody } from "discord-api-types/rest/v8";
- import { APIUnavailableGuild } from "discord-api-types/payloads/v8/guild";
+ import { APIUnavailableGuild } from "discord-api-types/payloads/v8";

Probably a build tag like build:ref-parent-module with a regex that matches an import, within that, find of last occurrence of / and delete until ".