0
# API Data
1
2
Web API interface inheritance relationships and mixin implementations that describe the structure of the Web API object model.
3
4
## Capabilities
5
6
### Inheritance Data Access
7
8
Access complete inheritance relationships for Web API interfaces.
9
10
```javascript { .api }
11
/**
12
* Web API interface inheritance data
13
* Maps interface names to their inheritance information
14
*/
15
const inheritance: InheritanceData;
16
17
interface InheritanceData {
18
[interfaceName: string]: InheritanceEntry;
19
}
20
21
interface InheritanceEntry {
22
/** The parent interface this interface inherits from, or null if no inheritance */
23
inherits: string | null;
24
/** Array of mixin interfaces this interface implements */
25
implements: string[];
26
}
27
```
28
29
**Usage Examples:**
30
31
```javascript
32
const { api } = require('mdn-data');
33
34
// Check what DocumentFragment inherits from
35
const docFragment = api.inheritance.DocumentFragment;
36
console.log(docFragment);
37
// Output: { "inherits": "Node", "implements": ["ParentNode", "LegacyQueryInterface"] }
38
39
// Find all interfaces that inherit from EventTarget
40
const eventTargetChildren = Object.entries(api.inheritance)
41
.filter(([name, data]) => data.inherits === 'EventTarget')
42
.map(([name]) => name);
43
44
// Check what mixins an interface implements
45
const analyserNode = api.inheritance.AnalyserNode;
46
console.log(analyserNode.implements);
47
// Output: ["AudioNodePassThrough"]
48
49
// Find interfaces with no parent (top-level interfaces)
50
const topLevelInterfaces = Object.entries(api.inheritance)
51
.filter(([name, data]) => data.inherits === null)
52
.map(([name]) => name);
53
```
54
55
### Interface Lookup
56
57
Direct access to specific interface inheritance information.
58
59
```javascript { .api }
60
/**
61
* Get inheritance information for a specific interface
62
* @param interfaceName - Name of the Web API interface
63
* @returns Inheritance entry or undefined if not found
64
*/
65
function getInheritanceInfo(interfaceName: string): InheritanceEntry | undefined {
66
return api.inheritance[interfaceName];
67
}
68
```
69
70
### Inheritance Tree Navigation
71
72
Helper patterns for navigating the inheritance hierarchy.
73
74
```javascript { .api }
75
/**
76
* Common patterns for working with inheritance data
77
*/
78
79
// Get all parent interfaces in the inheritance chain
80
function getInheritanceChain(interfaceName: string): string[] {
81
const chain = [];
82
let current = api.inheritance[interfaceName];
83
84
while (current && current.inherits) {
85
chain.push(current.inherits);
86
current = api.inheritance[current.inherits];
87
}
88
89
return chain;
90
}
91
92
// Get all child interfaces that inherit from a given interface
93
function getChildInterfaces(parentInterface: string): string[] {
94
return Object.entries(api.inheritance)
95
.filter(([name, data]) => data.inherits === parentInterface)
96
.map(([name]) => name);
97
}
98
99
// Get all interfaces that implement a specific mixin
100
function getInterfacesImplementingMixin(mixinName: string): string[] {
101
return Object.entries(api.inheritance)
102
.filter(([name, data]) => data.implements.includes(mixinName))
103
.map(([name]) => name);
104
}
105
```
106
107
## Data Structure Details
108
109
The inheritance data provides:
110
111
- **Complete Coverage**: All Web API interfaces with their inheritance relationships
112
- **Mixin Support**: Tracks which interfaces implement specific mixins
113
- **Null Inheritance**: Top-level interfaces have `inherits: null`
114
- **Empty Arrays**: Interfaces without mixins have `implements: []`
115
116
## Common Use Cases
117
118
1. **API Documentation Generation**: Understanding interface hierarchies for documentation tools
119
2. **Type System Integration**: Building TypeScript definitions or other type systems
120
3. **Polyfill Development**: Understanding what methods/properties are inherited
121
4. **Testing Frameworks**: Validating that implementations follow the correct inheritance model
122
5. **IDE Support**: Providing accurate autocomplete and error checking for Web APIs