Skip to content

Commit f345574

Browse files
committed
TypeScript type defintions docs for website
1 parent b0d7a0d commit f345574

File tree

8 files changed

+148
-0
lines changed

8 files changed

+148
-0
lines changed

docs/web/docs/features/web-standards/base64-utility-methods.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ function atob(data: string): string;
1111
function btoa(data: string): string;
1212
```
1313

14+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
15+
```ts
16+
@core-js/types/web/atob-btoa
17+
```
18+
1419
## [Entry points]({docs-version}/docs/usage#h-entry-points)
1520
```ts
1621
core-js(-pure)/stable|actual|full/atob

docs/web/docs/features/web-standards/iterable-dom-collections.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class [DOMTokenList, NodeList] {
4949
}
5050
```
5151

52+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
53+
```ts
54+
@core-js/types/web/iterable-dom-collections
55+
```
56+
5257
## [Entry points]({docs-version}/docs/usage#h-entry-points)
5358
```
5459
core-js(-pure)/stable|actual|full/dom-collections/iterator

docs/web/docs/features/web-standards/queuemicrotask.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
function queueMicrotask(fn: Function): void;
1010
```
1111

12+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
13+
```ts
14+
@core-js/types/web/queue-microtask
15+
```
16+
1217
## [Entry points]({docs-version}/docs/usage#h-entry-points)
1318
```ts
1419
core-js(-pure)/stable|actual|full/queue-microtask

docs/web/docs/features/web-standards/setimmediate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ function setImmediate(callback: any, ...args: Array<mixed>): number;
99
function clearImmediate(id: number): void;
1010
```
1111

12+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
13+
```ts
14+
@core-js/types/web/efficient-script-yielding
15+
```
16+
1217
## [Entry points]({docs-version}/docs/usage#h-entry-points)
1318
```ts
1419
core-js(-pure)/stable|actual|full/set-immediate

docs/web/docs/features/web-standards/structured-clone.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
function structuredClone(value: Serializable, { transfer?: Sequence<Transferable> }): any;
1010
```
1111

12+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
13+
```ts
14+
@core-js/types/web/structured-clone
15+
```
16+
1217
## [Entry points]({docs-version}/docs/usage#h-entry-points)
1318
```ts
1419
core-js(-pure)/stable|actual|full/structured-clone

docs/web/docs/features/web-standards/url-and-urlsearchparams.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class URLSearchParams {
4545
}
4646
```
4747

48+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
49+
```ts
50+
@core-js/types/web/url-to-json
51+
```
52+
4853
## [Entry points]({docs-version}/docs/usage#h-entry-points)
4954
```ts
5055
core-js/proposals/url

docs/web/docs/menu.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"title": "Supported engines and compatibility data",
88
"url": "{docs-version}/docs/engines"
99
},
10+
{
11+
"title": "TypeScript type definitions",
12+
"url": "{docs-version}/docs/typescript-type-definitions"
13+
},
1014
{
1115
"title": "Features",
1216
"children": [
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# TypeScript Type Definitions
2+
3+
This package contains types for the global and pure versions of `core-js`.
4+
Although `core-js` is a JavaScript standard library polyfill, the built-in TypeScript types are often not sufficient.
5+
Additional types are needed for:
6+
- features that are already in JavaScript but not yet in TypeScript’s standard types;
7+
- proposals, including those already implemented in JavaScript engines;
8+
- explicit imports of features from the pure version.
9+
10+
It is shipped as a separate package because we cannot guarantee stable behavior with future TypeScript releases, including minor ones.
11+
12+
## Installation
13+
```bash
14+
npm install --save @core-js/[email protected]
15+
```
16+
17+
## Usage
18+
Add to your `tsconfig.json`:
19+
```json
20+
{
21+
"compilerOptions": {
22+
"types": [
23+
"@core-js/types"
24+
]
25+
}
26+
}
27+
```
28+
or import it directly in your files:
29+
```ts
30+
import '@core-js/types';
31+
```
32+
`@core-js/types` includes all types and entry points for the global version, but it is recommended to select only the subset you actually use.
33+
34+
### Usage of subsets
35+
There are four main subsets:
36+
- `@core-js/types/actual` - types for all actual features, including stable ECMAScript, web standards and Stage 3 ECMAScript proposals;
37+
- `@core-js/types/es` - types for stable ECMAScript features only;
38+
- `@core-js/types/stable` - types for stable ECMAScript and web standards features;
39+
- `@core-js/types/full` - types for all features, including proposals.
40+
41+
You can import them the same way as the main package. For example, to use only the stable subset, add this to your `tsconfig.json`:
42+
```json
43+
{
44+
"compilerOptions": {
45+
"types": [
46+
"@core-js/types/stable"
47+
]
48+
}
49+
}
50+
```
51+
or import it directly in your files:
52+
```ts
53+
import '@core-js/types/stable';
54+
```
55+
56+
### Usage of specific features
57+
If you need types only for specific features, you can import them like this:
58+
```json
59+
{
60+
"compilerOptions": {
61+
"types": [
62+
"@core-js/types/proposals/array-unique",
63+
"@core-js/types/web/atob-btoa"
64+
]
65+
}
66+
}
67+
```
68+
or import them directly in your files:
69+
```ts
70+
import '@core-js/types/proposals/array-unique';
71+
import '@core-js/types/web/atob-btoa';
72+
```
73+
For a full list of available features, see the [documentation](https://core-js.io/v4/docs/).
74+
75+
## Types for the pure version
76+
### Base usage
77+
Add this to your `tsconfig.json`:
78+
```json
79+
{
80+
"compilerOptions": {
81+
"types": [
82+
"@core-js/types/pure"
83+
]
84+
}
85+
}
86+
```
87+
Then, when you import from the pure entry points, the corresponding types are picked up automatically:
88+
```ts
89+
import $findLast from '@core-js/pure/full/array/find-last';
90+
91+
$findLast([1, 3, 4, 2], v => v > 2); // => 4
92+
```
93+
94+
### Namespace usage in the pure version
95+
If you need to use multiple methods from the same namespace, you can add `@core-js/types/pure` to `tsconfig.json` and import the entire namespace:
96+
```ts
97+
import $array from '@core-js/pure/full/array';
98+
99+
$array.findLast([1, 3, 4, 2], v => v > 2);
100+
$array.flatMap([1, 2, 3], x => [x, x * 2]);
101+
```
102+
103+
## DOM types
104+
Some of the global types for web standards work correctly only with the DOM lib.
105+
You need to add DOM types to the `lib` section of your `tsconfig.json` in addition to `@core-js/types`. For example:
106+
```json
107+
{
108+
"compilerOptions": {
109+
"types": ["@core-js/types"],
110+
"lib": ["esnext", "dom"]
111+
}
112+
}
113+
```
114+
In the pure version, you can use these types without adding the DOM lib.

0 commit comments

Comments
 (0)