microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.02k stars 12.49k forks source link

"Extend this..." refactor #48898

Open brianjenkins94 opened 2 years ago

brianjenkins94 commented 2 years ago

I want to extend somebody else's types. In figuring out how to do so, I generally use "Go to Type Definition" to go and get a better idea of how the types are written so that I can figure out how to extend the types in question.

Then, without fail, I end up googling "typescript extend third-party types" and get answers from 2015-2018, ranging from "Based on how the definition is currently written you can't extend it externally" to "do this":

declare module "koa" {
    interface Context {
        resource: any;
    }
}

I find these really confusing to write (namespace vs. module vs. interface; should it be declare global?) and it requires a lot of guess and check.

It would be nice if I could right-click on an import or be able to have a "Quick fix" for Property 'foo' does not exist on type 'bar'. that would insert the appropriate code to extend that particular type.

(I don't actually think a "Quick fix" would be a good idea since that is in most cases not what you want to be doing, but hopefully you get my point).

Alternatively, maybe this is an opportunity for improvement on https://www.typescriptlang.org/docs/handbook/declaration-merging.html.

mjbvz commented 2 years ago

Sounds like a good candidate for a TypeScript service plugin