Setting up TypeScript definitions for Azure Media Player in Angular 10: A step-by-step guide

Having difficulty configuring the TypeScript definition for the Azure Media Player in an Angular 10 project. Using the *.d.ts file obtained from the official documentation

Attempted setting up the definition using typeRoots in the tsconfig.json file:

"typeRoots": [ "./src/types/", "./node_modules/@types"],

Encountered conflicting information on where to place the types folder, either at the root level or inside the src folder. Currently, the azuremediaplayer.d.ts file is located in ./src/types/azuremediaplayer/.

Error message in tsconfig file states

Cannot find type definition file for 'azuremediaplayer'.

In my component, copied code snippet from official documentation, excluding functions (causing errors).

ngOnInit(): void {
    var myPlayer = amp('vid1', {
      "nativeControlsForTouch": false,
      autoplay: false,
      controls: true,
      width: "640",
      height: "400",
      poster: ""
    });
    myPlayer.src([{
      src: "http://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest",
      type: "application/vnd.ms-sstr+xml"
    }])

  }

When clicking on amp function above, redirects to .d.ts file, yet certain parameters cause errors:

Argument of type '{ nativeControlsForTouch: boolean; autoplay: false; controls: true; width: string; height: string; poster: string; }' is not assignable to parameter of type 'Options'.

Object literal may only specify known properties, and '"nativeControlsForTouch"' does not exist in type 'Options'.

No errors occur when initialization is as follows:

var myPlayer = amp('vid1', {
      autoplay: false,
      controls: true,
      poster: ""
    });
    myPlayer.src([{
      src: "http://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest",
      type: "application/vnd.ms-sstr+xml"
    }])

  }

The player functions if instantiated in the HTML file.

Followed steps described in this answer: If reference file with

/// <reference path="../../../types/azuremediaplayer/azuremediaplayer.d.ts" />
, no changes are observed, without any errors in JSON. Adding file in files: [] property causes amp() to be unrecognized. Including
"include": ["src/**/*"]
results in similar issues as typeRoot, with corresponding errors.

What is the correct setup to ensure proper functionality of the player?

Answer №1

When implementing this feature in my React app with Typescript, I found it to be framework-agnostic. Here are the steps I took:

I placed the type definition file in the following directory:

src/video-player/amp/azuremediaplayer.min.d.ts

I updated my tsconfig.json file by adding a typeRoots property. Keep in mind that your project may have multiple typescript config files. In my case, I have the default one and a tsconfig.package.json for npm publishing purposes. Here's how my typeRoots configuration looks in both tsconfig files:

 "typeRoots": ["node_modules/@types", "src/video-player/amp"]

In my component's .tsx file, I can now utilize the amp typescript definition like so:

readonly options: amp.Player.Options;

Based on your explanation, it seems like you've set up typings correctly. Make sure that the version of the typings file matches the amp version from the CDN (I'm using version 2.3.5). If they align, there might be an issue or discrepancy in the official typings file - for example, the nativeControlsForTouch option appears in the minified script from the CDN but is missing from the typings file.

It's unfortunate that amp is not open-sourced and doesn't provide typings via npm. You can show your support for making amp open-source by voting here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Angular 5 routerLink for linking to absolute paths with hash symbols

I am facing an issue with a URL that needs to be opened in a new tab. Unfortunately, Angular generates this URL without the # symbol. Currently, we have implemented the following: <!-- HTML --> <a title="Edit" [routerLink] = "['/object/objec ...

handle HTTP errors within Observable.interval()

I have a block of code that runs every hour to a specific URL. Currently, if the URL is not found or returns a 500 error, I receive the error message. The application utilizes service workers, and functions properly when a valid URL is provided, triggering ...

What is the best way to host a single page application within a sub-directory using nginx?

Trying to set up nginx to host an Angular application from a unique child path. Adjusted the app to use a base href of fish, able to serve root page and assets correctly. However, encountering a 404 error when attempting to reload the page on a child rout ...

Adjust the component's input value using a different component

Let's talk about two components in this scenario - HomeComponent and UserComponent. The UserComponent is a child of the HomeComponent and has the following structure: UserComponent.html: <form [formGroup]="form"> <div style="display:block ...

Separate the string by commas, excluding any commas that are within quotation marks - javascript

While similar questions have been asked in this forum before, my specific requirement differs slightly. Apologies if this causes any confusion. The string I am working with is as follows - myString = " "123","ABC", "ABC,DEF", "GHI" " My goal is to spli ...

Create a SHA512 hashing algorithm using Angular framework

Is there a way to hash a string using SHA512 in Angular 2+? I have searched for libraries or functions to do so but haven't found any. Can you suggest a solution for this? ...

The TypeScript error TS7006 is indicating that the parameter '_' is assumed to have an undefined type

In my Angular application, I have a class that implements ControlValueAccessor from the '@angular/forms' library: export abstract class CustomControl implements ControlValueAccessor { private _value: any = ''; private onChange ...

Switching from the `async` pipe to `ngrxPush` for handling state updates in Angular

While utilizing Angular schematics for generating my Angular code, I came across the following line ngrx-push-migration - Migration to replace async pipe with ngrxPush This piqued my interest, so I decided to do some research and discovered The ngrxPu ...

When employing node.js's filesystem module, you may encounter an empty object as the result

Currently, I am working on a project using Angular 6 and Electron 4. When attempting to utilize the fs module from Node, I am encountering an issue where it returns an empty object. Below is the snippet of my code: import { Component } from '@angular ...

Angular: Concealing a Component within a Controller

Being new to Angular, I am trying to figure out how to programmatically hide/show a component using the controller. I am having trouble understanding how to access my component and set ng-hide to false. Currently, my controller includes a service call. Af ...

Retrieving variables from JavaScript files in TypeScript

Greetings, I am in the process of upgrading an existing Angular application from version 2 to 9. My approach involves first moving it to angular 4 and then continuing with the upgrades. I have successfully updated the necessary packages, but now I'm e ...

What processes occur behind the scenes when DownGit downloads specific files or folders from GitHub?

I was looking for a way to download specific files or folders from GitHub and discovered DownGit. However, I am curious about the inner workings of this tool. After reading the README.md on https://github.com/MinhasKamal/DownGit, I still couldn't ful ...

Adding a transition effect to a div in CSS when switching from col-12 to col-9

I am facing an issue with the CSS provided below. It seems to only work when I close my div with the class "onclick-div". However, the transition effect is not visible when I click on the button to reduce the width of the div with the class "set-transiti ...

A guide on verifying input for null with ngIf

I need to verify if the Comment is not null in order to display the div Error: Template parse issue - Unexpected closing tag "div". This error can occur if the tag has already been closed by another tag. For more information, please refer to: &l ...

Utilizing TypeScript with Sequelize for the Repository Design Pattern

I am in the process of converting my Express API Template to TypeScript, and I am encountering difficulties with the repositories. In JavaScript, the approach would be like this: export default class BaseRepository { async all() { return th ...

Generate a new Map<string, IDoSomethingWith<Something>> instance

Can anyone help me figure out how to instantiate a generic Map using TypeScript? Map<string, IDoSomethingWith<Something>> I attempted the following: const test: ReadonlyArray<string> = ['somekey']; new Map<string, IDoSomet ...

Implementing data binding for arrays of inputs in Angular

Can anyone provide assistance with this code snippet and explain why it is not functioning as expected? I am trying to generate input fields from a string array and bind each input value to its corresponding element in the array. It seems like a common tas ...

forwarding within afterCallback employing nextjs-auth0

I need to handle multiple cases for redirecting users based on various fields and custom claims in the user token, which involves navigating through complex if/else blocks. Let's consider a simpler example where I want to redirect the user to /email- ...

Ensure that the key and value types in a Typescript Map are strictly specified

Is it feasible to generate a map that consists of key-value pairs, where the key is represented by a string and the value corresponds to an object containing specific properties defined by mapValue? type mapValue { first: string; second: boolean; } Yo ...

Create dynamic breadcrumb trails using router paths

I am currently working on developing a streamlined breadcrumbs path for my application. My goal is to achieve this with the least amount of code possible. To accomplish this, I have implemented a method of listening to router events and extracting data fr ...