Skip to content

"Extend this..." refactor #48898

@brianjenkins94

Description

@brianjenkins94

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: Refactoringse.g. extract to constant or function, rename symbolSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions