Yui
Yui2y ago

module augmentation

Suppose module.ts is some external module that I have no control of. In my file test.ts I want to change the type UserEnv of the external module. How can I do this or does Deno just not support this and you basically need to use node to do this? Note: This is a simple example where I could technically use generics, but you cannot do that with bigger stuff.
7 Replies
Yui
Yui2y ago
module.ts
import type { Interaction } from "https://deno.land/x/discordeno@17.2.0/mod.ts";

// deno-lint-ignore no-empty-interface
interface UserEnv {}

export type CommandExecutor = (data: UserEnv) => void | Promise<void>;
export type Command = () => CommandExecutor;

export const tool = {
// deno-lint-ignore no-unused-vars
create: (data: Interaction): UserEnv => {
return {};
},
};
import type { Interaction } from "https://deno.land/x/discordeno@17.2.0/mod.ts";

// deno-lint-ignore no-empty-interface
interface UserEnv {}

export type CommandExecutor = (data: UserEnv) => void | Promise<void>;
export type Command = () => CommandExecutor;

export const tool = {
// deno-lint-ignore no-unused-vars
create: (data: Interaction): UserEnv => {
return {};
},
};
test.ts
import type { Interaction } from "https://deno.land/x/discordeno@17.2.0/mod.ts";
import { CommandExecutor, tool } from "./module.ts";

declare module "./module.ts" {
interface UserEnv {
data: Interaction;
appname: string;
}
}

tool.create = (data) => {
return { data, appname: "test" };
};

// deno-lint-ignore no-unused-vars
function testcommand(): CommandExecutor {



return (data) => {
// deno-lint-ignore no-unused-vars
const interaction = data.data;

// deno-lint-ignore no-unused-vars
const appname = data.appname;
};
}
import type { Interaction } from "https://deno.land/x/discordeno@17.2.0/mod.ts";
import { CommandExecutor, tool } from "./module.ts";

declare module "./module.ts" {
interface UserEnv {
data: Interaction;
appname: string;
}
}

tool.create = (data) => {
return { data, appname: "test" };
};

// deno-lint-ignore no-unused-vars
function testcommand(): CommandExecutor {



return (data) => {
// deno-lint-ignore no-unused-vars
const interaction = data.data;

// deno-lint-ignore no-unused-vars
const appname = data.appname;
};
}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Yui
Yui2y ago
yeah, seems like Deno does not support it.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Yui
Yui2y ago
If I turn off typechecking than yeah. (no --check flag)
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Yui
Yui2y ago
module augmentation stuff not working 😐