Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm just a hobbyist and have some scriplets I've written to "improve" things on various websites. As part of that I needed an uninstall/undo feature - so with my "bush league" code I would do `window.mything = {something}`, and based upon previous dabblings with the likes of python/c#/go, I presumed I would be able to do `delete window.mything` and it would auto-magically call a function I would have written to do the work. So the new `[Symbol.dispose]()` feature/function would have done what I was looking for - but really, it;s not a big deal, because all that I actually had to do was write an interface spec'ing `{}.remove()` method, and call it where needed.

(This paragraph is getting off topic, but still... ) Below is my exact interface that I have in a .d.ts file. The reason for that file is because I like typed languages (ie TypeScript), but I don't want to install stuff like node-js for such simple things. So I realised vscode can/will check js files as ts on-the-go, so in a few spots (like this) I needed to "type" something - and then I found some posts about svelte source code using js-docs to type their code-base instead of typescript. So that's basically what I've done here...

  export global {
    interface Window {
        MyThing?: {remove: ()=>any}
    }
  }
So chances are that in the places you could use this feature, you've probably already got an "interface" for closing things when done (even if you haven't defined the interface in a type system).


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: