microsoft / TypeScript

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

Do not return 'declare' or 'add index signature' quick fixes for types that are part of lib.d.ts #29482

Closed mjbvz closed 5 years ago

mjbvz commented 5 years ago

TypeScript Version: typescript@3.3.0-dev.20190118

Search Terms:

Code

For the code:

async function a() {
    const response = await fetch(`https://example.com`);
   response.jsonX();
}

Trigger quickfixes on jsonX

Bug declare and add index quick fixes returned. These modify the dom.d.ts declarations of fetch.

screen shot 2019-01-18 at 11 27 01 am

We should never try to edit the lib.d.ts files

Playground Link:

Related Issues:

mjbvz commented 5 years ago

One other fun case with declaration merging:

interface Response{
    stuff: any;
}

async function a() {
    const response = await fetch(`https://example.com`);
   response.jsonX();
}

In this case, it may make sense to show the declare quick fixes as long as they only modify the Response interface in the file and not the Response interface from dom.d.ts. Or we could just choose to never show these quick fixes for types that are from lib.d.ts