hls.js icon indicating copy to clipboard operation
hls.js copied to clipboard

hls.js/light Events type is an empty object

Open roderickdecorrespondent opened this issue 8 months ago • 5 comments

What version of Hls.js are you using?

1.6.15

What browser (including version) are you using?

Vivaldi 7.8.3925.76 (Official Build) (arm64), Chromium 144.0.7559.238

What OS (including version) are you using?

macOS 15.7.4 (24G517)

Test stream

No response

Configuration

{}

Additional player setup steps

No response

Checklist

  • [x] The issue observed is not already reported by searching on Github under https://github.com/video-dev/hls.js/issues
  • [x] The issue occurs in the stable client (latest release) on https://hlsjs.video-dev.org/demo and not just on my page
  • [x] The issue occurs in the latest client (main branch) on https://hlsjs-dev.video-dev.org/demo and not just on my page
  • [x] The stream has correct Access-Control-Allow-Origin headers (CORS)
  • [x] There are no network errors such as 404s in the browser console when trying to play the stream

Steps to reproduce

import Hsl from 'hsl.js/light';
Hsl.Events.MEDIA_ATTACHED // TS error: Property 'MEDIA_ATTACHED' does not exist on type '{}'

The full build works as expected:

import Hsl from 'hsl.js';
Hsl.Events.MEDIA_ATTACHED // All good

This is in Visual Studio Code 1.109.5, with [email protected]

Expected behaviour

I expect the light build to include the types so I don't have to @ts-expect-error

What actually happened?

I get a TS error.

Console output

N/A

Chrome media internals output


roderickdecorrespondent avatar Mar 10 '26 12:03 roderickdecorrespondent

Make sure you import is pulling from the .mjs ESM light file and not the UMD ES5 .js file that exports only Hls.

robwalch avatar Mar 10 '26 17:03 robwalch

Can you provide steps to reproduce with a repl page?

robwalch avatar Mar 10 '26 17:03 robwalch

Thanks for the quick reply!

Looks like VCS is pulling the right file (mjs), but can't find the d.ts for it:

Could not find a declaration file for module 'hls.js/light'. 
'.../node_modules/hls.js/dist/hls.light.mjs' implicitly has an 'any' type.`

Looking at the /dist folder, it looks like there should be a hls.light.d.ts file or something like it? Or something in hls.light.mjs which points to the hls.d.ts file?

(Sorry I'm not super familiar with typescript, primarily a "user")

I'll try and find some time tomorrow to create a repro.

roderickdecorrespondent avatar Mar 10 '26 17:03 roderickdecorrespondent

Update: just added the config below to our jsconfig.js, and that seems to make it work:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "hls.js/light": ["node_modules/hls.js/dist/hls.js.d.ts"]
    }
  }
}

roderickdecorrespondent avatar Mar 10 '26 17:03 roderickdecorrespondent

Looks like VCS is pulling the right file (mjs), but can't find the d.ts for it

The build only produces one set of type definitions with tsc --build tsconfig-lib.json.

build:copy-types makes copies of that output to "hls.d.mts" and "hls.js.d.ts". You can submit a PR to make additional "light" copies to solve look up.

robwalch avatar Mar 11 '26 21:03 robwalch