-
Notifications
You must be signed in to change notification settings - Fork 137
Support modifying global types #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is coming from JSR. JSR does not currently allow global declarations. See https://jsr.io/docs/about-slow-types#global-augmentation. cc @dsherret - we should consider allowing global declarations in entrypoints maybe. |
Cheers 🙏🏻 Not sure how I can use JSR for this specific package (and probably others) as I often need to let TypeScript know of some globals like Web Components created and new events that will fire. Another good example would be something like this: https://github.com/github/tab-container-element/blob/21f1e2b8dcc43d7905dbe806e508ea6e510e0d9e/src/tab-container-element-define.ts#L18-L24 |
Global augmentation is really useful. declare module 'cordis' { // declare the types for `kv_store`
kv_store: MyStore
}
class MyStore extends cordis.Service {
constructor(ctx: cordis.Context, options: {}) {
super(ctx, 'kv_store') // inject as `kv_store` in Context
}
get(/*...*/) { /*...*/ }
set(/*...*/) { /*...*/ }
}
function main() {
const ctx = new cordis.Context()
const scope = ctx.plugin(MyStore, { ... }) // installs the plugin
ctx.inject(['kv_store'], (ctx) => { // kv_store now available under the Context
// you can now easily use `kv_store` without coupling,
// the underlying implementation can be easily changed to anything with same interface.
// hmr in backends could also be possible with cordis.
ctx.kv_store.set("foo", "bar")
ctx.kv_store.get("foo") === "bar";
scope.dispose() // dispose all side-effect of the plugin (also unregisters the inject)
typeof ctx.get('kv_store') === "undefined" // `kv_store` is gone
})
} You can inject a Other plugins could |
Linking the issue from the Deno repo here: denoland/deno#23427 |
Please considerate this as an option, I can't publish my library on JSR only for this error. |
jsx namesapce also needs this option, i can not publish https://github.com/ije/html to jsr.io, help 🙏
|
I'm not sure where this error is coming from. Is it from
jsr
or TypeScript or somewhere else? How can I fix it?Example run here: https://github.com/koddsson/context-protocol/actions/runs/8480796983/job/23237140188
The text was updated successfully, but these errors were encountered: