OK mine is less adorable, but I appreciate TypeScript namespaces
I really love them. I think it is so cool to be able to organize types, functions, constants inside a single unit. I really enjoy the explicitness at usage sites of the namespace, too. They also have some interesting quirks where a type, class, or function can even be a namespace!
// data-itemz.ts
export namespace DataItemz {
export interface Type {
name: string;
cost: Integer;
}
export const manifest = {
burger: {
cost: 999,
name: "Delicious Burger",
},
cheeseburger: {
cost: 1,
name: "Undelicious Cheeseburger",
},
} satisfies Record<string, Type>;
}
// player.ts or something
function eatItem(player: Player, item: DataItemz.Type) {
player.health += 1;
console.log(`Wonderful. It tasted like it cost ${item.cost} money.`);
}
I think they are being deprecated in some future version of TS though. I will probably not use that version, as I find this so pleasing!!!