From 29b938cd41effce6e5c0e03adf7a116acc66ce1b Mon Sep 17 00:00:00 2001 From: Michael Barlock Date: Fri, 5 Jan 2024 09:38:49 -0500 Subject: [PATCH] add typescript documentation --- .gitignore | 1 + src/mdx-pages/guides/typescript.mdx | 35 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/mdx-pages/guides/typescript.mdx diff --git a/.gitignore b/.gitignore index ee4f4a04..864d4e10 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,7 @@ yarn-error.log # IDE *.swp .tags +.idea # Now now.json diff --git a/src/mdx-pages/guides/typescript.mdx b/src/mdx-pages/guides/typescript.mdx new file mode 100644 index 00000000..69b7c7f4 --- /dev/null +++ b/src/mdx-pages/guides/typescript.mdx @@ -0,0 +1,35 @@ +--- +title: Typescript +category: advanced +description: Using Video.js with Typescript. +--- + +Starting with Video.js 8.0, types are included in the npm package. This documentation are for the included types. If you are using 7.0 or below you can use the [DefinitelyTyped](https://www.npmjs.com/package/@types/video.js) package and see their documentation. + +## Usage + +In general, you should be able to use Video.js with Typescript without any extra steps. If you are using advanced features of video.js you might need to pull in some internal types. You can find them in the `video.js/dist/types` package. + +```ts +// A few examples + +import type Player from 'video.js/dist/types/player'; +import type Plugin from 'video.js/dist/types/plugin'; +import type Component, {ComponentOptions} from 'video.js/dist/types/component'; +``` + +## Plugins + +If you are writing a plugin, you can use module augmentation to add types to the `videojs` namespace. + +```ts +declare module 'video.js/dist/types/player' { + interface Player { + // videojs-contrib-quality-levels + qualityLevels: { + VERSION: string; + (): QualityLevelList; + }; + } +} +```