-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Shaka Typescript definition overriding Google Cast Sender with incomplete defs #3185
Comments
That makes sense. We should ideally not generate definitions for things that are not exposed by us. I don't believe the Cast API is exposed through ours. The trouble is that some of the true external types that we depend on are exposed through our API, and without those definitions, the generated definitions for Shaka Player would be incomplete. I'm not sure the right way to address this in the general case. |
I confirm this bug. Currently, we are on v3.0.5, and when I tried to upgrade to v3.0.8 got many errors about intersections with Chromecast types. If required I can provide more details |
|
Partially fixes shaka-project#1030. The issue was created to track a problem using Shaka from a Typescript project. Inside the issue, a fix was contributed by @alexandercerutti, although it was acknowledged that the fix was not a complete fix. Event types are still missing, for instance. Having said that, it seems the main reason that @alexandercerutti's partial fix wasn't applied is that @joeyparrish expressed a desire for a small Typescript sample to be added as an automated test to verify that this works. Changes 1) Modified generateTsDefs.py to apply the partial fix by @alexandercerutti. 2) While testing, I discovered that the Windows build produces a broken .d.ts, because the bytes on Windows (b'?_?.clutz.') are different than Linux (b'\xe0\xb2\xa0_\xe0\xb2\xa0.clutz.'). Fixed by adding a second replace pattern for Windows. Since the two are mutually exclusive, I just run them serially without condition. 3) While verifying, I noticed some unreplaced clutz namespaces. These occur because instead of ".clutz." the pattern is ".clutz ". I looked into a couple, they seem to have been supplied because the Closure compiler lacks declarations. Added Linux and Windows replacement lines to assign these to the "shakaExterns" namespace. 4) Added a simple Typescript compilation test. I structured the tsconfig.json to look like a typical usage case where shaka-player is imported as a node module. Note that if we set skipLibCheck to false, this leads to the errors described in Issue shaka-project#3185, eg. error TS2694: Namespace 'google.ima.dai.api' has no exported member 'StreamRequest' (also mentioned in Issue shaka-project#1030). NOTE that when this test fails, I couldn’t figure out how to get the compiler output on-screen, so instead I provide instructions for re-running the test interactively, which will produce the error on-screen. Testing Procedure 1) python build/test.py. Confirm pass. 2) Verify that some of the previously unreplaced clutz namespaces, such as ಠ_ಠ.clutz.AirPlayEvent, are no longer under the ಠ_ಠ.clutz prefix and instead are under the shakaExterns namespace, and that you can compile successfully. 3) Repeat both of the above steps under both Linux and Windows. Confirm that the produced .d.ts files differ only in the comments, where the source file path is stated.
Is there a workaround? We are stuck with shaka-player 3.0.5 in angular 11 project. |
Not sure it's about interaction with other libraries. Even the simplest TS project doesn't compile. // index.ts
import { polyfill, Player } from 'shaka-player';
polyfill.registerAll();
const player = new Player();
player.load('https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd'); Compiling: $ npm install shaka-player typescript
[... installs shaka-player@3.2.1, typescript@4.4.4]
$ npx tsc --lib dom,es2015 index.ts
index.ts:1:34 - error TS2306: File '/redacted/node_modules/shaka-player/dist/shaka-player.compiled.d.ts' is not a module.
1 import { polyfill, Player } from 'shaka-player';
~~~~~~~~~~~~~~
node_modules/shaka-player/dist/shaka-player.compiled.d.ts:489:62 - error TS2694: Namespace 'google.ima.dai.api' has no exported member 'StreamRequest'.
[...]
Found 10 errors. Only workaround I found was to delete the |
Just wanted to leave a comment here, as I ran into this issue today as well (as mentioned by @philippe-elsass-deltatre above). I wanted to try out shaka drm capabilities with a simple Angular project (following the official guide), but adjusting for webpack (import * as shaka from 'shaka-player'; etc), but I found myself forced to go with the suggested approach in the guide, adding Any word on this would be greatly appreciated. If Shaka performs to my expectations then I'm very much interested in migrating to the Shaka Player in my webapp. |
Honestly for now I have to stay with latest 2.x (2.5.9). It's stable and doesn't get in the way. |
We are also stuck on an old version with no end in sight |
We apologize for the generated Typescript definitions. This is not a Typescript-native project, and the tools we are using to generate the definitions are clearly not able to do everything we need. I will increase the priority of this issue. In the meantime, you may wish to work around the issue with hand-written definitions to import Shaka Player into your Typescript project. We apologize for the inconvenience. |
Any updates on this? :) Maybe someone else can provide their workaround? |
Current workaround: a post-install script deleting all the |
what is the script? |
|
Types are generated but exports is not defined. So you can either remove types or follow up on my suggestions.
All files and step-by-step instructions can be found at the following link: |
@Security2431 how do you think is it possible to remove some built-in plugins from compiled code using For avoiding https://github.com/shaka-project/shaka-player/blob/main/docs/tutorials/plugins.md#excluding-default-plugins this |
@siarheipashkevich You can remove 'em from import. However, they'll still up in node_modules. What is the end purpose of it? |
I want to decrease the bundle size of my player. Right now shaka used ~500kb. |
@siarheipashkevich Ah, I see the point. Well, it's not your case though. |
@Security2431 could you please ping me in TG |
Question/Suggestion on this: Would it be better to prevent .d.ts files from being shipped with the npm package since it breaks typescript projects by default? Maybe they could be provided else where so we could include them and modify them as needed in the project with copy/paste? |
Hi @joeyparrish, I was taking a look and I see that making to only include content of --- a/build/build.py
+++ b/build/build.py
@@ -316,7 +316,7 @@ class Build(object):
return False
generated_externs = [extern_generator.output]
- shaka_externs = shakaBuildHelpers.get_all_js_files('externs')
+ shaka_externs = shakaBuildHelpers.get_all_js_files('externs/shaka')
if self.has_ui():
shaka_externs += shakaBuildHelpers.get_all_js_files('ui/externs')
ts_def_generator = compiler.TsDefGenerator( Do you think it will have another unwanted effect or can I submit a PR? |
Have you read the FAQ and checked for duplicate open issues?
Yes, this does probably relate to #1030, but I assume it is cleaner to report it as a separate bug.
What version of Shaka Player are you using?
3.0.8
Can you reproduce the issue with our latest release version?
NA
Can you reproduce the issue with the latest code from
master
?Not tested
Are you using the demo app or your own custom app?
Own
If custom app, can you reproduce the issue using our demo app?
NA
What browser and OS are you using?
Any
For embedded devices (smart TVs, etc.), what model and firmware version are you using?
NA
What are the manifest and license server URIs?
NA
What did you do?
In code unrelated to the Shaka based player Typescript gives errors, example:
What did you expect to happen?
Type from
node_modules/@types/chrome/chrome-cast/index.d.ts
to be resolved. (That is included when using the@types/chromecast-caf-sender
package.)What actually happened?
Type from
node_modules/shaka-player/dist/shaka-player.compiled.d.ts
seems to override, in this case:Which does not contain the
addMediaListener
method.I see there are similar issues reported for IMA types in #1030, maybe Shaka should not export these definitions for 'externs'? or maybe not in the global scope at least?
The text was updated successfully, but these errors were encountered: