Skip to content

Commit 59a6bca

Browse files
authored
🤖 Merge PR DefinitelyTyped#72672 [elm] allow specifying Elm.* namespace by @lishaduck
1 parent cf9edbf commit 59a6bca

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

types/elm/.eslintrc.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"rules": {
3-
"@definitelytyped/no-type-only-packages": "off",
4-
"@typescript-eslint/no-unsafe-function-type": "off",
5-
"@typescript-eslint/no-wrapper-object-types": "off",
6-
"@typescript-eslint/no-empty-interface": "off"
3+
"@definitelytyped/no-type-only-packages": "off"
74
}
85
}

types/elm/elm-tests.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
declare var Elm: ElmInstance<ShanghaiPorts>;
1+
declare var Elm: ElmInstance<{}, {}>;
2+
3+
Elm.Main.init();
4+
5+
declare var Shanghai: ElmInstance<
6+
ShanghaiPorts,
7+
ShanghaiFlags, // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
8+
["Shanghai"]
9+
>;
10+
11+
interface ShanghaiFlags {
12+
coordinates: [number, number];
13+
incomingShip: Ship;
14+
outgoingShip: string;
15+
}
216

317
interface ShanghaiPorts {
4-
coordinates: PortToElm<number[]>;
18+
coordinates: PortToElm<[number, number]>;
519
incomingShip: PortToElm<Ship>;
620
outgoingShip: PortToElm<string>;
721
totalCapacity: PortFromElm<number>;
@@ -14,15 +28,15 @@ interface Ship {
1428

1529
// initialize the Shanghai component which keeps track of
1630
// shipping data in and out of the Port of Shanghai.
17-
var shanghai = Elm.Main.init({
31+
var shanghai = Shanghai.Shanghai.init({
1832
flags: {
1933
coordinates: [0, 0],
2034
incomingShip: { name: "", capacity: 0 },
2135
outgoingShip: "",
2236
},
2337
});
2438

25-
function logger(x: any) {
39+
function logger(x: number) {
2640
console.log(x);
2741
}
2842
shanghai.ports.totalCapacity.subscribe(logger);

types/elm/index.d.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
interface ElmInstance<P = {}> {
2-
Main: ElmMain<P>;
3-
}
1+
type ElmInstance<
2+
P,
3+
F,
4+
Entrypoints extends string[] =
5+
// eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
6+
["Main"],
7+
> = NestedEntrypoints<Entrypoints, P, F>;
8+
9+
type NestedEntrypoints<Entrypoints extends string[], P, F> = Entrypoints extends [
10+
infer First extends string,
11+
...infer Rest extends string[],
12+
] ? { [K in First]: NestedEntrypoints<Rest, P, F> }
13+
: ElmMain<P, F>;
414

5-
interface ElmMain<P> {
6-
init(options: { node?: Node | undefined; flags?: any }): ElmApp<P>;
15+
interface ElmMain<P, F> {
16+
init(options?: { node?: Node | undefined; flags: F } | undefined): ElmApp<P>;
717
}
818

919
interface ElmApp<P> {

types/elm/tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
"es6",
66
"dom"
77
],
8-
"noImplicitAny": true,
9-
"noImplicitThis": true,
10-
"strictNullChecks": true,
11-
"strictFunctionTypes": true,
8+
"strict": true,
9+
"exactOptionalPropertyTypes": true,
1210
"types": [],
1311
"noEmit": true,
1412
"forceConsistentCasingInFileNames": true

0 commit comments

Comments
 (0)