File: contextualTypingOfOptionalMembers.js

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (103 lines) | stat: -rw-r--r-- 2,574 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//// [index.tsx]
interface ActionsObject<State> {
    [prop: string]: (state: State) => State;
}

interface Options<State, Actions> {
    state?: State;
    view?: (state: State, actions: Actions) => any;
    actions: string | Actions;
}

declare function app<State, Actions extends ActionsObject<State>>(obj: Options<State, Actions>): void;

app({
    state: 100,
    actions: {
        foo: s => s // Should be typed number => number
    },
    view: (s, a) => undefined as any,
});


interface Bar {
    bar: (a: number) => void;
}

declare function foo<T extends Bar>(x: string | T): T;

const y = foo({
    bar(x) { // Should be typed number => void
    }
});

interface Options2<State, Actions> {
    state?: State;
    view?: (state: State, actions: Actions) => any;
    actions?: Actions;
}

declare function app2<State, Actions extends ActionsObject<State>>(obj: Options2<State, Actions>): void;

app2({
    state: 100,
    actions: {
        foo: s => s // Should be typed number => number
    },
    view: (s, a) => undefined as any,
});


type ActionsArray<State> = ((state: State) => State)[];

declare function app3<State, Actions extends ActionsArray<State>>(obj: Options<State, Actions>): void;

app3({
    state: 100,
    actions: [
        s => s // Should be typed number => number
    ],
    view: (s, a) => undefined as any,
});

namespace JSX {
    export interface Element {}
    export interface IntrinsicElements {}
}

interface ActionsObjectOr<State> {
    [prop: string]: ((state: State) => State) | State;
}

declare function App4<State, Actions extends ActionsObjectOr<State>>(props: Options<State, Actions>["actions"] & { state: State }): JSX.Element;

const a = <App4 state={100} foo={s => s} />; // TODO: should be number => number, but JSX resolution is missing an inferential pass


//// [index.jsx]
app({
    state: 100,
    actions: {
        foo: function (s) { return s; } // Should be typed number => number
    },
    view: function (s, a) { return undefined; }
});
var y = foo({
    bar: function (x) {
    }
});
app2({
    state: 100,
    actions: {
        foo: function (s) { return s; } // Should be typed number => number
    },
    view: function (s, a) { return undefined; }
});
app3({
    state: 100,
    actions: [
        function (s) { return s; } // Should be typed number => number
    ],
    view: function (s, a) { return undefined; }
});
var a = <App4 state={100} foo={function (s) { return s; }}/>; // TODO: should be number => number, but JSX resolution is missing an inferential pass