Skip to content

Commit ffec7ed

Browse files
authored
Merge pull request #1500 from zloirock/v4-types
2 parents c41e850 + 69cd5ef commit ffec7ed

File tree

601 files changed

+14975
-541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

601 files changed

+14975
-541
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ jobs:
2121
- run: pip install codespell
2222
- run: npx run-s lint-raw codespell
2323

24+
type-definitions:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v6
28+
- uses: actions/setup-node@v6
29+
with:
30+
node-version: 25
31+
cache: npm
32+
- run: npm run prepare-monorepo
33+
- run: npx run-s build-types test-type-definitions-ci
34+
2435
karma:
2536
runs-on: windows-2022
2637
steps:

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ node_modules/
4545
/packages/core-js-pure/proposals/
4646
/packages/core-js-pure/stable/
4747
/packages/core-js-pure/stage/
48-
/packages/core-js-pure/index.js
4948
/packages/core-js-pure/configurator.js
49+
/packages/core-js-pure/index.js
5050
/packages/core-js-pure/package.json
5151
/packages/core-js-pure/LICENSE
52+
/packages/core-js-types/package.json
53+
/packages/core-js-types/ts*
54+
/packages/core-js-types/LICENSE
5255
/tests/**/bundles/
5356
/tests/compat/*.jar
5457
/tests/compat/compat-data.js
5558
/tests/unit-global/index.js
5659
/tests/unit-pure/index.js
60+
/tests/type-definitions/tmp/
5761
/website/templates/
5862
/website/dist/
5963
/website/src/public/

CONTRIBUTING.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There is always some ["help wanted" issues](https://github.com/zloirock/core-js/
1616
- For export the polyfill, in all common cases use [`internals/export`](./packages/core-js/modules/export.js) helper. Use something else only if this helper is not applicable - for example, if you want to polyfill accessors.
1717
- If the code of the pure version implementation should significantly differ from the global version (*that's not a frequent situation, in most cases [`internals/is-pure`](./packages/core-js/modules/is-pure.js) constant is enough*), you can add it to [`packages/core-js-pure/override`](./packages/core-js-pure/override) directory. The rest parts of `@core-js/pure` will be copied from `core-js` package.
1818
- Add the feature detection of the polyfill to [`tests/compat/tests.js`](./tests/compat/tests.js), add the compatibility data to [`packages/core-js-compat/src/data.mjs`](./packages/core-js-compat/src/data.mjs), how to do it [see below](#how-to-update-core-js-compat-data).
19-
- Add it to entries definitions, see [`scripts/build-entries/entries-definitions.mjs`](./scripts/build-entries/entries-definitions.mjs).
19+
- Add it to entries definitions, see [`scripts/build-entries-and-types/entries-definitions.mjs`](scripts/build-entries-and-types/entries-definitions.mjs).
2020
- Add unit tests to [`tests/unit-global`](./tests/unit-global) and [`tests/unit-pure`](./tests/unit-pure).
2121
- Add tests of entry points to [`tests/entries/unit.mjs`](./tests/entries/unit.mjs).
2222
- Make sure that you are following [our coding style](#style-and-standards) and [all tests](#testing) are passed.
@@ -65,6 +65,33 @@ engine | how to run tests | base data inherits from | mandatory ch
6565

6666
If you have no access to all required browsers / versions of browsers, use [Sauce Labs](https://saucelabs.com/), [BrowserStack](https://www.browserstack.com/) or [Cloud Browser](https://ieonchrome.com/).
6767

68+
## TypeScript type definitions
69+
70+
- TypeScript definitions should be added to the [`packages/core-js-types/src/base`](./packages/core-js-types/src/base) directory.
71+
- Our type definitions are built on top of ES6. If any related type is missing in ES6, it must be added to the [`packages/core-js-types/src/base/core-js-types`](./packages/core-js-types/src/base/core-js-types) directory and imported via triple-slash directives in your type definition file.
72+
- Place your type definition into the folder that matches its kind ([`packages/core-js-types/src/base/proposals`](./packages/core-js-types/src/base/proposals), [`packages/core-js-types/src/base/web`](./packages/core-js-types/src/base/web)).
73+
- Type definitions for the pure version are either generated from the global version types or created manually in the [`packages/core-js-types/src/base/pure`](./packages/core-js-types/src/base/pure) folder. Type build rules for the pure version can be modified using the `@type-options` directive:
74+
- `no-extends` – do not extend the base type when adding a prefix to the type/interface
75+
- `no-prefix` – do not add a prefix to the type/interface name
76+
- `no-constructor` – use it when the type has no constructor (for example, `Math`)
77+
- `export-base-constructor` – export the base type’s constructor instead of the prefixed one
78+
- `no-export` – do not export this type
79+
- `no-redefine` – do not redefine the type’s constructor
80+
- `prefix-return-type` – add a prefix to the return type
81+
- All type definitions must be covered by TSC tests. Add them to the [`tests/type-definitions`](./tests/type-definitions) directory.
82+
- To build the types, run the command:
83+
```sh
84+
npm run build-types
85+
```
86+
- To test the types, run the command:
87+
```sh
88+
npm run test-type-definitions-all
89+
```
90+
- To run the fast subset of the types test, run the command:
91+
```sh
92+
npm run test-type-definitions-smoke
93+
```
94+
6895
## Style and standards
6996

7097
The coding style should follow our [`eslint.config.js`](./tests/eslint/eslint.config.js). You can test it by calling [`npm run lint`](#testing). Different places have different syntax and standard library limitations:

docs/web/docs/features/proposals/accessible-object-prototype-hasownproperty.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ class Object {
1313
```plaintext
1414
core-js/proposals/accessible-object-hasownproperty
1515
```
16+
17+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
18+
[`@core-js/types/proposals/accessible-object-hasownproperty`](https://github.com/zloirock/core-js/blob/v4-types/packages/core-js-types/src/base/proposals/accessible-object-hasownproperty.d.ts)

docs/web/docs/features/proposals/array-deduplication.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ core-js(-pure)/full/array(/prototype)/unique-by
2222
core-js/full/typed-array/unique-by
2323
```
2424

25+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
26+
[`@core-js/types/proposals/array-unique`](https://github.com/zloirock/core-js/blob/v4-types/packages/core-js-types/src/base/proposals/array-unique.d.ts)
27+
2528
## Examples
2629
```js
2730
[1, 2, 3, 2, 1].uniqueBy(); // [1, 2, 3]

docs/web/docs/features/proposals/array-filtering.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ core-js(-pure)/full/array(/prototype)/filter-reject
2323
core-js/full/typed-array/filter-reject
2424
```
2525

26+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
27+
[`@core-js/types/proposals/array-filtering`](https://github.com/zloirock/core-js/blob/v4-types/packages/core-js-types/src/base/proposals/array-filtering.d.ts)
28+
2629
## Examples
2730
```js
2831
[1, 2, 3, 4, 5].filterReject(it => it % 2); // => [2, 4]

docs/web/docs/features/proposals/array-find-from-last.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ class %TypedArray% {
1919
```plaintext
2020
core-js/proposals/array-find-from-last
2121
```
22+
23+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
24+
[`@core-js/types/proposals/array-find-from-last`](https://github.com/zloirock/core-js/blob/v4-types/packages/core-js-types/src/base/proposals/array-find-from-last.d.ts)

docs/web/docs/features/proposals/array-fromasync.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ class Array {
1313
```plaintext
1414
core-js/proposals/array-from-async
1515
```
16+
17+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
18+
[`@core-js/types/proposals/array-from-async`](https://github.com/zloirock/core-js/blob/v4-types/packages/core-js-types/src/base/proposals/array-from-async.d.ts)

docs/web/docs/features/proposals/array-grouping.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ class Map {
1717
```plaintext
1818
core-js/proposals/array-grouping-v2
1919
```
20+
21+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
22+
[`@core-js/types/proposals/array-grouping`](https://github.com/zloirock/core-js/blob/v4-types/packages/core-js-types/src/base/proposals/array-grouping.d.ts)

docs/web/docs/features/proposals/array-istemplateobject.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ core-js/proposals/array-is-template-object
1818
core-js(-pure)/full/array/is-template-object
1919
```
2020

21+
## [TypeScript type definitions]({docs-version}/docs/typescript-type-definitions)
22+
[`@core-js/types/proposals/array-is-template-object`](https://github.com/zloirock/core-js/blob/v4-types/packages/core-js-types/src/base/proposals/array-is-template-object.d.ts)
23+
2124
## Example
2225
```js
2326
console.log(Array.isTemplateObject((it => it)`qwe${ 123 }asd`)); // => true

0 commit comments

Comments
 (0)