types-webdeprecated

Provides TypeScript types for the latest web APIs.

Usage no npm install needed!

<script type="module">
  import typesWeb from 'https://cdn.skypack.dev/types-web';
</script>

README

types-web

Get types for the latest web APIs as soon as they become widely available!

An example showing types for MediaSession and MediaRecorder

The default types generator for TypeScript requires manual review for every update, and thus does not provide types for every latest API in a timely manner. types-web solves this issue by deploying automation by following tools:

  • @mdn/browser-compat-data provides which features are supported by which browsers, so that undersupported features can be disabled automatically.
  • webref provides IDL code from the specs, so that the features can be properly typed.

See how many types have been added in the changelog.

How to use

  1. Install the package by npm i types-web.

  2. Include the type files in your tsconfig.json or jsconfig.json:

    {
      "compilerOptions": {
        // Explicitly exclude "dom" here
        "lib": ["es2020"]
      },
      "includes": [
        // For general scripts: dom*
        // Web workers: webworker*
        // Shared workers: sharedworker*
        // Service workers: serviceworker*
        // Audio worklets: audioworklet*
        "node_modules/types-web/baselines/dom*"
        "*"
      ]
    }
    

Why not @types?

To maintain the package by myself without waiting for external reviews.

Why is my fancy API still not available here?

A feature needs to be supported by more than two major browser engines to be included here, to make sure there is a good consensus among vendors: Gecko (Firefox), Blink (Chrome/Edge), and WebKit (Safari).

If the condition is met but still is not available here, please file an issue.

Is it fully automated?

Not yet. A small part of things still needs manual modification, which is done by files in inputfiles/ directory.

Build Instructions

  • To get things setup:

    npm i
    
  • To generate the .d.ts files

    npm run build && npm run baseline-accept
    
  • To test:

    npm test