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.
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
muslnode 18–226 runs
build_error
glibcnode 18–226 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();
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.