Registry / type-stubs / new-javascript

new-javascript

JSON →
library0.4.7jsnpmunverified

This package, `new-javascript`, provides TypeScript type definitions for cutting-edge and experimental Web APIs and JavaScript features that are not yet incorporated into TypeScript's standard `dom` library or `@types/web`. As of version 0.4.7, it covers a wide range of specifications from groups like WICG, including the File System Access API, View Transitions, and Compression Streams. The project's release cadence is driven by the evolution of these web standards and TypeScript's integration schedule. A key differentiator is its proactive approach to providing types for early-stage APIs, using automated WebIDL-to-TypeScript conversion with manual refinement. It also uniquely includes worker-exclusive interfaces by default and offers specific type declarations for various worklet types through distinct import paths, helping developers target specific environments.

type-stubsweb-framework
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

This package primarily provides global type augmentations, not runtime values. Types are typically included via reference directives in TypeScript files or by listing 'new-javascript' in the `compilerOptions.types` array in `tsconfig.json`.

/// <reference types="new-javascript" />

Specific worklet environments like AudioWorklets require their own dedicated reference paths to ensure correct global type augmentation for those contexts. Direct `import type` statements are not the intended mechanism for these global augmentations.

/// <reference types="new-javascript/worklet/audio" />

Similar to AudioWorklets, PaintWorklet types are provided via a specific reference path. Using the correct `/// <reference>` directive ensures the browser's global scope is correctly augmented for PaintWorklet development.

/// <reference types="new-javascript/worklet/paint" />

Demonstrates how to install and configure `new-javascript` types via `tsconfig.json` and a reference directive, then utilizes types from the File System Access API and View Transitions API in a runnable TypeScript example.

npm i -D new-javascript@latest // tsconfig.json // { // "compilerOptions": { // "types": ["new-javascript"], // "lib": ["dom", "dom.iterable", "esnext"] // } // } // Example TypeScript file (e.g., src/main.ts) /// <reference types="new-javascript" /> async function demonstrateNewApiUsage() { // Using File System Access API types, like FileSystemFileHandle if ('showOpenFilePicker' in window) { try { const [fileHandle] = await window.showOpenFilePicker(); console.log('File picked:', fileHandle.name); const file = await fileHandle.getFile(); console.log('File size:', file.size, 'bytes'); // Additional operations with fileHandle or file } catch (error) { if (error instanceof DOMException && error.name === 'AbortError') { console.log('File picker was dismissed.'); } else { console.error('Error with File System Access API:', error); } } } else { console.warn('File System Access API not supported by this browser.'); } // Using View Transitions API types, like document.startViewTransition if (document.startViewTransition) { console.log('View Transitions API is supported. Starting a transition.'); const transition = document.startViewTransition(() => { // Perform DOM updates that trigger the transition const contentDiv = document.getElementById('content-area'); if (contentDiv) { contentDiv.innerHTML = `<h2>Content updated at ${new Date().toLocaleTimeString()}</h2><p>This is new content.</p>`; } return Promise.resolve(); }); try { await transition.finished; console.log('View transition completed successfully.'); } catch (error) { console.error('View transition failed:', error); } } else { console.warn('View Transitions API not supported by this browser.'); } } demonstrateNewApiUsage();
Debug
Known footguns
gotchaAs this package provides type definitions for experimental or rapidly evolving Web APIs, there is a significant potential for future type conflicts or duplications once official definitions are integrated into TypeScript's standard `dom` library or other `@types` packages. This can lead to `Duplicate identifier` errors during compilation.
gotchaThis package includes type definitions for worker-exclusive interfaces (e.g., `FileReaderSync`, `FileSystemSyncAccessHandle`) by default. If your project is exclusively for the main thread, these types may incorrectly suggest the availability of APIs not present in that context, potentially leading to runtime errors if used.
gotchaThe APIs type-declared in `new-javascript` are often from WICG or other draft specifications, meaning their interfaces and behaviors are subject to change. This can lead to breaking type changes in future minor versions of `new-javascript` as it strives to align with the latest drafts, potentially requiring code adjustments without a major version bump of the package.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
10 hits · last 30 days
gptbot
4
ahrefsbot
3
script
1
bytedance
1
googlebot
1
Resources