Skip to content

Conversation

@sleeyax
Copy link
Member

@sleeyax sleeyax commented Sep 11, 2025

Closes #291.

Initially, I went with the approach suggested by the linked issue; i.e. to transpile JSDoc comments to typescript declaration files (.d.ts). But then I realized that wasn't the best approach because:

  • The JSDocs comments take up a lot of space, pushing down the actual implementation code
  • The JSDoc comments are more limited compared to declaration files (e.g. no imports)
  • Stremio web also contains custom declaration files, indicating the Stremio team is already familiar with it

Thus, I decided to declare the declaration files directly. Another plus is this doesn't require a build step nor the typescript devDependency.

I also updated the types to match the latest SDK version, as they were a little outdated.

I tested the changes locally with yalc and my own addons, most importantly Easynews+ which up until now used to rely on some typescript hacks to work well with the sdk. Besides my own human eyes I also leveraged AI (gh copilot + claude sonnet 4) to validate my changes against the documentation and everything appears to check out.

This PR makes the community @types/stremio-addon-sdk package obsolete going forward.

Next steps:

  • Bump the addon sdk package version
  • (optional) document typescript support and declare the community package as deprecated somewhere in the readme? It should be noted that the community package is still useful for older versions of the addon sdk.
  • (optional) document advanced typescript usage. The most noteworthy thing users should know is that their custom configuration objects can be typed as follows:
type Config = {
  username: string;
  password: string;
};

// ...
builder.defineStreamHandler<Config>(
  async ({ id, type, config: { username, password } }) => {
     // ^ all arguments above are properly typed
    // ...
  }
);

Because:
- The JSDocs comments take up a lot of space, pushing down the actual implementation code
- The JSDoc comments are more limited compared to declaration files (e.g. no imports)
- Stremio web also uses `.d.ts` files so the team is already familiar with it
serveHTTP: require('./serveHTTP'),
getRouter: require('./getRouter'),
publishToCentral: require('./publishToCentral'),
landingTemplate: require('./landingTemplate'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: The EN+ addon, and likely others as well, rely on this function. In the past, I worked around this by importing it directly from stremio-addon-sdk/src/landingTemplate, but that approach no longer works with TypeScript due to type restrictions. This seems like a good opportunity to properly export the function so that users can import it directly from stremio-addon-sdk, regardless of whether they’re using plain JavaScript or TypeScript.

@sleeyax
Copy link
Member Author

sleeyax commented Sep 12, 2025

Build is failing because of this:

# publishToCentral

not ok 40 [object Object]

  ---

    operator: error

    expected: |-

      undefined

    actual: |-

      { code: 9908, message: 'Invalid addon publish - too many addons published. Please try again latter' }

    at: <anonymous> (/home/travis/build/Stremio/stremio-addon-sdk/test/basic.js:216:6)

    stack: |-

      Error: [object Object]

          at Test.assert [as _assert] (/home/travis/build/Stremio/stremio-addon-sdk/node_modules/tape/lib/test.js:225:54)

          at Test.bound [as _assert] (/home/travis/build/Stremio/stremio-addon-sdk/node_modules/tape/lib/test.js:77:32)

          at Test.error.Test.ifError.Test.ifErr.Test.iferror (/home/travis/build/Stremio/stremio-addon-sdk/node_modules/tape/lib/test.js:373:10)

          at Test.bound [as error] (/home/travis/build/Stremio/stremio-addon-sdk/node_modules/tape/lib/test.js:77:32)

          at /home/travis/build/Stremio/stremio-addon-sdk/test/basic.js:216:6

          at processTicksAndRejections (internal/process/task_queues.js:95:5)

  ...

1..40

# tests 40

# pass  39

# fail  1

This seems like a bug/issue unrelated to this PR?

@kKaskak kKaskak self-requested a review October 7, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add typescript types

2 participants