EventEmitter types still broken on Typescript 3.9 RC
See original GitHub issueTypescript 3.9, which should be out some time this week, still has an error when compiling
Here’s my tsconfig:
{
"compilerOptions": {
"strict": true,
"lib": ["esnext", "dom"],
"types": []
}
}
And my index.ts:
import eventemitter3 = require("eventemitter3");
The error is here:
export type EventListener<
T extends ValidEventTypes,
K extends EventNames<T>
> = T extends string | symbol
? (...args: any[]) => void
: (...args: ArgumentMap<T>[K]) => void; // error
“Type ‘K’ cannot be used to index type ‘ArgumentMap<T>’.”
I can’t tell what’s going wrong from a quick glance at the types; there are too many layers of indirection here. My guess is that the compiler just can’t find a declaration that says K
is a legal key of ArgumentMap<T>
— but I couldn’t figure out what declaration would work.
Discovered in the Typescript nightly tests, where we compile our nightly against the latest shipped types of widely used packages: https://github.com/microsoft/TypeScript/pull/38405
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Documentation - TypeScript 3.9
This goal of this type operator is to accurately model the way that Promise unwrapping works in JavaScript. We initially anticipated shipping awaited...
Read more >"Type 'EventEmitter' is not generic" ERROR in angular
Even in the angular website it looks like that code is correct. I'm currently using Angular CLI: 1.7.4; Node: 8.11.1; Typescript: 2.8.1.
Read more >web3-core-promievent | Yarn - Package Manager
This is the PromiEvent package used to return a EventEmitter mixed with a Promise to allow multiple final states as well as chaining....
Read more >Become a ninja with Angular sample - Angularjs - 16
instead (2016-06-09) Pipes • Date pipe is now fixed in rc.2, no more problem with Intl API (2016-06-16) Styling components and encapsulation •...
Read more >TypeScript Programming with Visual Studio Code
js , you'll see that it doesn't look very different from helloworld.ts . The type information has been removed and let is now...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That works for me, and is basically the workaround discussed in the PR that introduced the breaking change, which means that it should be a pretty safe change.
I think I’ve found a solution by using
Exclude
.Can you verify that this works for you as well and that this won’t cause any unintended side effects?