背景:我正在移植带有 video.js 和插件的 jQuery 应用程序。到 TypeScript React 应用程序。
尝试将 video.js 当前版本 8.3.0 与 TypeScript 和第 3 方插件一起使用会导致类型错误,例如:Property 'playlist' does not exist on type 'Player'。
应该注意的是,这个设置实际上可以在生产环境中使用多个插件,但是 TS 服务器会抛出错误。
import { useRef } from 'react';
import videojs from 'video.js';
import type Player from 'video.js/dist/types/player';
import 'videojs-playlist';
const videoElement = document.createElement('video-js');
const playerRef = useRef<Player | null>(null);
const playlist = [{...}];
const options = {...};
const player = (playerRef.current = videojs(videoElement, options));
player.autoplay(false);
player.playlist(playlist); // TS Error: Property …Run Code Online (Sandbox Code Playgroud)