Skip to content
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

Event类的 raiseEvent 方法的类型声明错误 #10498

Closed
GuoBinyong opened this issue Jun 30, 2022 · 3 comments
Closed

Event类的 raiseEvent 方法的类型声明错误 #10498

GuoBinyong opened this issue Jun 30, 2022 · 3 comments

Comments

@GuoBinyong
Copy link

原来的类型声明是

    /**
     * Raises the event by calling each registered listener with all supplied arguments.
     * @param arguments - This method takes any number of parameters and passes them through to the listener functions.
     */
    raiseEvent(...arguments: Parameters<Listener>[]): void;

这会导致必须要参数必须要放到数组里,如下:

raiseEvent([[arg1,arg2]])

这是原码中的逻辑不一样,而且因为要多加个中括号,这也使得使用体验也不好

正确的类型声明应该如下:

    raiseEvent(...arguments: Parameters<Listener>): void;
@ggetz
Copy link
Contributor

ggetz commented Jul 5, 2022

@thw0rted
Copy link
Contributor

thw0rted commented Jul 6, 2022

Well this is a pickle.

In JSDoc, the rest-type operator ... assumes each spread parameter is the same, so {...Object} means the parameter would be an array of Object. Following this spec, tsd-jsdoc automatically converts the specified type to an array.

In Typescript, ...args: SomeTuple means that the rest-parameter would get a tuple type, an array of known length, with different types in each position. That's why I started to respond that this is a bug in tsd-jsdoc, because of course it shouldn't turn ...Object into Object[], but apparently that's the syntax that JSDoc chose. Worse, there's probably no point in complaining to JSDoc, because 1) they don't have a concept of tuples, and 2) the project is basically dead, so there's effectively zero chance of seeing support added.

I'm going to take this up with tsd-jsdoc, and probably Typescript as well, and report back. In the meantime I'm really not sure how to proceed. We may have to revert L122/L123 to {...Object} for now.

@thw0rted
Copy link
Contributor

thw0rted commented Jul 6, 2022

The issue I made on tsd-jsdoc automatically linked here. I also made microsoft/TypeScript#49801. Hopefully between them, we can figure something out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants