GithubHelp home page GithubHelp logo

[8.14.1] Type errors about video.js HOT 11 OPEN

boris-petrov avatar boris-petrov commented on July 3, 2024
[8.14.1] Type errors

from video.js.

Comments (11)

mister-ben avatar mister-ben commented on July 3, 2024 1

It looks like jsdoc is ok with using @param {function():void} fn ? The API docs output defines it as a function, and the type definition becomes ready(fn: () => void, sync?: boolean): void;. Seems simpler than defining ReadyCallback.

from video.js.

gkatsev avatar gkatsev commented on July 3, 2024

The ready method comes from Component, which Player inherits from. ready on a component, would have the this be that Component, which, in the case of Player, would be the player.
We don't override the method in player.js, but maybe we can use jsdoc to update the method signature there?

from video.js.

boris-petrov avatar boris-petrov commented on July 3, 2024

I'm not sure, maybe overriding the type signature is possible. This is not that important if it's difficult to fix as users can cast the usage in the function so it's kind-of OK. The other problem with the return type is breaking all usages of ready though.

from video.js.

gkatsev avatar gkatsev commented on July 3, 2024

yeah, these two lines should be removed. Not sure why they were re-added the last time that piece was touched:

* @return {Component}
* Returns itself; method can be chained.

from video.js.

boris-petrov avatar boris-petrov commented on July 3, 2024

I guess that is wrong, yes, because I don't see the code returning anything from ready. But will that fix the other issue that the fn argument is marked as returning Component? I don't understand how this maps to the fn parameter? I see fn defined as a ReadyCallback above this but I don't find a definition for ReadyCallback anywhere in the codebase.

from video.js.

mister-ben avatar mister-ben commented on July 3, 2024

ReadyCallback is here, but I don't know why that is interpreted as it would return a Component

/**
* A callback that is called when a component is ready. Does not have any
* parameters and any callback value will be ignored.
*
* @callback ReadyCallback
* @this Component
*/

from video.js.

boris-petrov avatar boris-petrov commented on July 3, 2024

Looking in VSCode, when I hover over ReadyCallback, the tooltip says type ReadyCallback = /*unresolved*/ any. I'm not sure how this @callback annotation works. But maybe because TS can't resolve ReadyCallback it thinks that the line below (which says @return {Component}) also applies to it? But on the other hand I see that fn is defined with this: Component so it did somehow read the definition of ReadyCallback... I'm not sure, all these jsdoc annotations are really strange. πŸ˜„

from video.js.

mister-ben avatar mister-ben commented on July 3, 2024

It's all very complicated because typescript understands a subset of jsdoc when generating the types, and also some typescript-specific syntax in jsdoc but which jsdoc itself doesn't understand, and breaks generating the API docs. Finding a balance that works for both is hard.

If I remove the @return from ready() and add @return {undefined} in Component.js, then component.d.ts has this:

ready(fn: () => undefined, sync?: boolean): void;

from video.js.

boris-petrov avatar boris-petrov commented on July 3, 2024

This also doesn't work, the return type must be void. Doesn't @return {void} work? Or simply removing @return?

from video.js.

mister-ben avatar mister-ben commented on July 3, 2024

{function():void} seems to work by accident rather than design, and would break jsdoc if it were any more complicated, e.g. documenting arguments. So not a good precedent to set. Going back to defined callbacks, I have this, which specifies this for the Player's callback but leaves Component's unspecified. Returning {void} isn't really right in jsdoc itself as js functions that don't explicitly return do return undefined. But it's probably well understood. Any thoughts?

from video.js.

boris-petrov avatar boris-petrov commented on July 3, 2024

I'm really not the person to review JSDoc. πŸ˜„ But as for the undefined - of course JavaScript itself doesn't have a concept of void but TypeScript does - and that's absolutely the right way to specify this function as it indeed does not return a value (even though there is an implicit return at runtime).

from video.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.