Skip to content

Commit dfaf486

Browse files
committed
🏷️ Add types for core-js-compat as upstream is missing them currently
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent e8988c7 commit dfaf486

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

src/core-js-compat.d.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
type ModuleName = string;
2+
3+
type Target =
4+
| 'android'
5+
| 'bun'
6+
| 'chrome'
7+
| 'chrome-android'
8+
| 'deno'
9+
| 'edge'
10+
| 'electron'
11+
| 'firefox'
12+
| 'firefox-android'
13+
| 'hermes'
14+
| 'ie'
15+
| 'ios'
16+
| 'node'
17+
| 'opera'
18+
| 'opera-android'
19+
| 'phantom'
20+
| 'quest'
21+
| 'react-native'
22+
| 'rhino'
23+
| 'safari'
24+
| 'samsung';
25+
26+
type TargetVersion = string;
27+
28+
type StringOrRegExp = string | RegExp;
29+
30+
type Modules = StringOrRegExp | readonly StringOrRegExp[];
31+
32+
type BrowserslistQuery = string | ReadonlyArray<string>;
33+
34+
type Environments = {
35+
[target in Target]?: string | number;
36+
};
37+
38+
type Targets = Environments & {
39+
browsers?: Environments | BrowserslistQuery,
40+
esmodules?: boolean,
41+
};
42+
43+
type CompatOptions = {
44+
/** entry / module / namespace / an array of them, by default - all `core-js` modules */
45+
modules?: Modules,
46+
/** a blacklist, entry / module / namespace / an array of them, by default - empty list */
47+
exclude?: Modules,
48+
/** optional browserslist or core-js-compat format query */
49+
targets?: Targets | BrowserslistQuery,
50+
/** used `core-js` version, by default the latest */
51+
version?: string,
52+
/** inverse of the result, shows modules that are NOT required for the target environment */
53+
inverse?: boolean,
54+
/**
55+
* @deprecated use `modules` instead
56+
*/
57+
filter?: Modules
58+
};
59+
60+
type CompatOutput = {
61+
/** array of required modules */
62+
list: ModuleName[],
63+
/** object with targets for each module */
64+
targets: {
65+
[module: ModuleName]: {
66+
[target in Target]?: TargetVersion
67+
}
68+
}
69+
}
70+
71+
declare function compat(options?: CompatOptions): CompatOutput
72+
73+
declare module 'core-js-compat' {
74+
const ExportedCompatObject: typeof compat & {
75+
compat: typeof compat,
76+
77+
/** map of modules by `core-js` entry points */
78+
entries: {[entry_point: string]: readonly ModuleName[]},
79+
80+
/** Full list of modules */
81+
modules: readonly ModuleName[]
82+
}
83+
84+
export = ExportedCompatObject
85+
}

0 commit comments

Comments
 (0)