#provide users on my NPM package with additional d.ts file

1 messages · Page 1 of 1 (latest)

round vortex
#

I like how TS adds a window global variable to my intellisense when I add "DOM" to the lib in the config

I am creating an npm package and I want my users to have their typescript provide global ambient definitions like window when you manually include "DOM" in the lib.
In my package repo I have the following file

// src/game.d.ts
declare function play(): void

there is no ts/js module that implements this function, only this one ambient declaration exists, there must not be implementation for this in my situation
I want my user to be able to write

// some-file.ts
play()

right after installing my package and this will work as if they themselves created this declaration file in their project. In other words, I want their TS to see more that there actually is.

My another idea is that i may create a "initializer" so that the user will be forced to use cli with npm <my-package> add game, this command, and they will have this d.ts auto-generated somewhere in there project. But I still want to hide this gigantic 1500+ loc declaration file behind the wall of my package so as not bother users at all.

Is the first approach even possible?

spring tartan
#

merge it into the Window interface

#

wait do you want to also have it accessible directly?