@t15i/webidl-decorators
v1.1.1
Published
A set of TypeScript decorators that let you declare [WebIDL](https://webidl.spec.whatwg.org/) interfaces, attributes, and special operations directly on classes. The runtime semantics — platform object behavior, indexed/named property access, setters, and
Readme
webidl-decorators - TypeScript decorators for WebIDL interfaces
A set of TypeScript decorators that let you declare
WebIDL interfaces, attributes, and special
operations directly on classes. The runtime semantics — platform object
behavior, indexed/named property access, setters, and deleters — are provided
by @t15i/webspecs.
Coverage is intentionally narrow — this is a knowledge base, not a polyfill. Only the decorators that have been ported so far are listed below; everything else is marked with
....
Install
npm install @t15i/webidl-decoratorsUsage
All decorators are exposed from a single entry point:
import {
Interface,
Attribute,
IndexedPropertyGetter,
NamedPropertyGetter,
// ...
} from "@t15i/webidl-decorators";Decorate a class with @Interface and any of its members with the appropriate
decorators. Once instantiated, the class behaves as a WebIDL platform object:
import { Interface, Attribute, IndexedPropertyGetter } from "@t15i/webidl-decorators";
import { Nullable, Type, UnsignedLong } from "@t15i/webspecs/webidl";
@Interface
class HTMLCollection {
@Attribute(UnsignedLong)
get length(): number {
// ...
}
@IndexedPropertyGetter(Nullable(Type(Element)))
item(index: number): Element | null {
// ...
}
}The decorator proposal used is the TC39 stage-3 / 2023-11 variant. Make sure your toolchain supports it.
What's implemented
Expand a section to see what is currently ported. ... marks sections with
un-ported content.
- §2 Interface definition language
- §2.2 Interfaces
- [x]
@Interface
- [x]
- §2.5 Members
- §2.5.2 Attributes
- [x]
@Attribute
- [x]
- §2.5.6 Special operations
- §2.5.6.1 Indexed properties
- [x]
@IndexedPropertyGetter - [x]
@IndexedPropertySetter - [x]
@IndexedPropertyDeterminator - [x]
@NewIndexedPropertySetter - [x]
@ExistingIndexedPropertySetter - [x]
@SupportedPropertyIndices
- [x]
- §2.5.6.2 Named properties
- [x]
@NamedPropertyGetter - [x]
@NamedPropertySetter - [x]
@NamedPropertyDeleter - [x]
@NamedPropertyDeterminator - [x]
@NewNamedPropertySetter - [x]
@ExistingNamedPropertySetter - [x]
@ExistingNamedPropertyDeleter - [x]
@SupportedPropertyNames
- [x]
- ...
- §2.5.6.1 Indexed properties
- ...
- §2.5.2 Attributes
- ...
- §2.2 Interfaces
- §3 ECMAScript binding
- §3.4 Legacy extended attributes
- §3.4.9 [LegacyUnenumerableNamedProperties]
- [x]
@LegacyUnenumerableNamedProperties
- [x]
- ...
- §3.4.9 [LegacyUnenumerableNamedProperties]
- ...
- §3.4 Legacy extended attributes
- ...
