diff --git a/.gitignore b/.gitignore index ee4f4a0..864d4e1 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 0000000..69b7c7f --- /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; + }; + } +} +```