Skip to content

Commit 97ff1a0

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

File tree

9 files changed

+156
-6
lines changed

9 files changed

+156
-6
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ function btoa(data: string): string;
1212
```
1313

1414
## [Entry points]({docs-version}/docs/usage#h-entry-points)
15-
```ts
15+
```plaintext
1616
core-js(-pure)/stable|actual|full/atob
1717
core-js(-pure)/stable|actual|full/btoa
1818
```
1919

20+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
21+
```plaintext
22+
@core-js/types/web/atob-btoa
23+
```
24+
2025
## Examples
2126
```js
2227
btoa('hi, core-js'); // => 'aGksIGNvcmUtanM='

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ class [DOMTokenList, NodeList] {
5050
```
5151

5252
## [Entry points]({docs-version}/docs/usage#h-entry-points)
53-
```
53+
```plaintext
5454
core-js(-pure)/stable|actual|full/dom-collections/iterator
5555
core-js/stable|actual|full/dom-collections/entries
5656
core-js/stable|actual|full/dom-collections/keys
5757
core-js/stable|actual|full/dom-collections/values
5858
core-js/stable|actual|full/dom-collections/for-each
5959
```
6060

61+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
62+
```plaintext
63+
@core-js/types/web/iterable-dom-collections
64+
```
65+
6166
## Examples
6267
```js
6368
for (let { id } of document.querySelectorAll('*')) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ function queueMicrotask(fn: Function): void;
1010
```
1111

1212
## [Entry points]({docs-version}/docs/usage#h-entry-points)
13-
```ts
13+
```plaintext
1414
core-js(-pure)/stable|actual|full/queue-microtask
1515
```
1616

17+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
18+
```plaintext
19+
@core-js/types/web/queue-microtask
20+
```
21+
1722
## Example
1823
```js
1924
queueMicrotask(() => console.log('called as microtask'));

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ function clearImmediate(id: number): void;
1010
```
1111

1212
## [Entry points]({docs-version}/docs/usage#h-entry-points)
13-
```ts
13+
```plaintext
1414
core-js(-pure)/stable|actual|full/set-immediate
1515
core-js(-pure)/stable|actual|full/clear-immediate
1616
```
1717

18+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
19+
```plaintext
20+
@core-js/types/web/efficient-script-yielding
21+
```
22+
1823
## Examples
1924
```js
2025
setImmediate((arg1, arg2) => {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ function structuredClone(value: Serializable, { transfer?: Sequence<Transferable
1010
```
1111

1212
## [Entry points]({docs-version}/docs/usage#h-entry-points)
13-
```ts
13+
```plaintext
1414
core-js(-pure)/stable|actual|full/structured-clone
1515
```
1616

17+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
18+
```plaintext
19+
@core-js/types/web/structured-clone
20+
```
21+
1722
## Examples
1823
```js
1924
const structured = [{ a: 42 }];

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,19 @@ class URLSearchParams {
4646
```
4747

4848
## [Entry points]({docs-version}/docs/usage#h-entry-points)
49-
```ts
49+
```plaintext
5050
core-js/proposals/url
5151
core-js(-pure)/stable|actual|full/url
5252
core-js(-pure)/stable|actual|full/url/can-parse
5353
core-js/stable|actual|full/url/to-json
5454
core-js(-pure)/stable|actual|full/url-search-params
5555
```
5656

57+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
58+
```plaintext
59+
@core-js/types/web/url-to-json
60+
```
61+
5762
## Examples
5863
```js
5964
URL.canParse('https://login:[email protected]:8080/?a=1&b=2&a=3&c=4#fragment'); // => true

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+
```sh
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.

website/src/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import javascript from 'highlight.js/lib/languages/javascript';
44
import typescript from 'highlight.js/lib/languages/typescript';
55
import json from 'highlight.js/lib/languages/json';
66
import bash from 'highlight.js/lib/languages/bash';
7+
import plaintext from 'highlight.js/lib/languages/plaintext';
78
import RunButtonPlugin from './hljs-run.js';
89

910
hljs.registerLanguage('js', javascript);
1011
hljs.registerLanguage('ts', typescript);
1112
hljs.registerLanguage('json', json);
1213
hljs.registerLanguage('sh', bash);
14+
hljs.registerLanguage('plaintext', plaintext);
1315

1416
let initialized = false;
1517
function init() {

0 commit comments

Comments
 (0)