-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Declaration file for @implements
of type specified in .d.ts
file includes broken syntax
#38640
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
I think #36292 missed implementing the declaration part, as the relevant code appears to be https://github.com/microsoft/TypeScript/blame/d07e866a28879f38d8cf7aea2a1b030de26613cc/src/compiler/transformers/declarations.ts#L1365-L1371 I am going to take a stab at that tomorrow, as this issue is blocking various files from being typechecked by TypeScript in DevTools. |
The above code link is incorrect. The I haven't been able to figure out why |
I only now found out that there is an existing test added in #36292 that already tests this behavior: https://github.com/microsoft/TypeScript/pull/36292/files#diff-06896a35c64292ec693e38ae9d4691a9R7 I am now trying to figure out what the difference is between these two test cases and why one fails and the other one doesn't. |
The difference appears to be the fact that the interface in our example is defined in a namespace. The existing test tests with a global interface. E.g. this works: // @filename: defs.d.ts
interface Global_Dispatcher {
foobar(): number;
}
// @filename: main.js
/**
* @implements {Global_Dispatcher}
*/
export class DispatcherImpl {
foobar() {
return 42;
};
} And this fails: // @filename: defs.d.ts
declare namespace Global {
export interface Dispatcher {
foobar(): number;
}
}
// @filename: main.js
/**
* @implements {Global.Dispatcher}
*/
export class DispatcherImpl {
foobar() {
return 42;
};
} |
It’s probably related to the fact that
Originally posted by @sKopheK in #35629 (comment) |
Over lunch, I realized that we can take advantage of the subtle difference in the previous comment. Essentially the following compiles successfully: // @filename: defs.d.ts
declare namespace Global {
export interface Dispatcher {
foobar(): number;
}
}
interface GlobalWorkaround_Dispatcher extends Global.Dispatcher {}
// @filename: main.js
/**
* @implements {GlobalWorkaround_Dispatcher}
*/
export class DispatcherImpl {
foobar() {
return 42;
};
} Solution implemented at https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2208978/ |
@ExE-Boss They could be related yes. However, TSC correctly checks the actual definition. E.g. it will warn when methods mismatch or when the type doesn't exist. It only goes wrong when it tries to write the actual declaration file. |
The TypeScript compiler has a bug where, when you implement an interface in JSDoc which is defined in a `.d.ts` file which uses a namespace, it generates an invalid declaration file [1]. To workaround this bug, we have to add global interfaces that are essentially aliases of the actual interfaces. As a result, the TypeScript compiler no longer fails with resolving. Update Closure accordingly such that we can use the correct type to work in both Closure and TypeScript. [1]: microsoft/TypeScript#38640 [email protected],[email protected] [email protected],[email protected] Bug: 1081686, 1011811 Change-Id: I088a4520c90ce0873cf9850a8ed65f9c8dd896ef Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2208978 Reviewed-by: Paul Lewis <[email protected]> Commit-Queue: Tim van der Lippe <[email protected]>
@ExE-Boss like the implements clause, Not sure if that's related to @TimvdLippe's bug though. |
I have a preliminary fix up at #38688, but it still has a couple of open questions. |
The TypeScript compiler has a bug where, when you implement an interface in JSDoc which is defined in a `.d.ts` file which uses a namespace, it generates an invalid declaration file [1]. To workaround this bug, we have to add global interfaces that are essentially aliases of the actual interfaces. As a result, the TypeScript compiler no longer fails with resolving. Update Closure accordingly such that we can use the correct type to work in both Closure and TypeScript. [1]: microsoft/TypeScript#38640 [email protected],[email protected] [email protected],[email protected] Bug: 1081686, 1011811 Change-Id: I088a4520c90ce0873cf9850a8ed65f9c8dd896ef Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2208978 Reviewed-by: Paul Lewis <[email protected]> Commit-Queue: Tim van der Lippe <[email protected]>
TypeScript Version: 4.0.0-dev.20200512
Search Terms: implements, jsdoc, declaration
Code
file.js
:defs.d.ts
:tsconfig.json
:Expected behavior:
Output declaration file
file.d.ts
:Actual behavior:
The syntax in this declaration file is broken and shows the following error:
Playground Link: n/a
Related Issues: #35629 implemented in #36292 CC @sandersn @dragomirtitian
The text was updated successfully, but these errors were encountered: