File: callsOnComplexSignatures.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 (169 lines) | stat: -rw-r--r-- 4,769 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//// [callsOnComplexSignatures.tsx]
/// <reference path="/.lib/react16.d.ts" />
import React from "react";

// Simple calls from real usecases
function test1() {
    type stringType1 = "foo" | "bar";
    type stringType2 = "baz" | "bar";

    interface Temp1 {
        getValue(name: stringType1): number;
    }

    interface Temp2 {
        getValue(name: stringType2): string;
    }

    function test(t: Temp1 | Temp2) {
        const z = t.getValue("bar"); // Should be fine
    }
}

function test2() {
    interface Messages {
        readonly foo: (options: { [key: string]: any, b: number }) => string;
        readonly bar: (options: { [key: string]: any, a: string }) => string;
    }

    const messages: Messages = {
        foo: (options) => "Foo",
        bar: (options) => "Bar",
    };

    const test1 = (type: "foo" | "bar") =>
        messages[type]({ a: "A", b: 0 });
}

function test3(items: string[] | number[]) {
    items.forEach(item => console.log(item));
}

function test4(
    arg1: ((...objs: {x: number}[]) => number) | ((...objs: {y: number}[]) => number),
    arg2: ((a: {x: number}, b: object) => number) | ((a: object, b: {x: number}) => number),
    arg3: ((a: {x: number}, ...objs: {y: number}[]) => number) | ((...objs: {x: number}[]) => number),
    arg4: ((a?: {x: number}, b?: {x: number}) => number) | ((a?: {y: number}) => number),
    arg5: ((a?: {x: number}, ...b: {x: number}[]) => number) | ((a?: {y: number}) => number),
    arg6: ((a?: {x: number}, b?: {x: number}) => number) | ((...a: {y: number}[]) => number),
) {
    arg1();
    arg1({x: 0, y: 0});
    arg1({x: 0, y: 0}, {x: 1, y: 1});

    arg2({x: 0}, {x: 0});

    arg3({x: 0});
    arg3({x: 0}, {x: 0, y: 0});
    arg3({x: 0}, {x: 0, y: 0}, {x: 0, y: 0});

    arg4();
    arg4({x: 0, y: 0});
    arg4({x: 0, y: 0}, {x: 0});

    arg5();
    arg5({x: 0, y: 0});
    arg5({x: 0, y: 0}, {x: 0});

    arg6();
    arg6({x: 0, y: 0});
    arg6({x: 0, y: 0}, {x: 0, y: 0});
    arg6({x: 0, y: 0}, {x: 0, y: 0}, {y: 0});
}

// JSX Tag names
function test5() {
    // Pair of non-like intrinsics
    function render(url?: string): React.ReactNode {
        const Tag = url ? 'a' : 'button';
        return <Tag>test</Tag>;
    }

    // Union of all intrinsics and components of `any`
    function App(props: { component:React.ReactType }) {
        const Comp: React.ReactType = props.component;
        return (<Comp />);
    }

    // custom components with non-subset props
    function render2() {
        interface P1 {
            p?: boolean;
            c?: string;
        }
        interface P2 {
            p?: boolean;
            c?: any;
            d?: any;
        }

        var C: React.ComponentType<P1> | React.ComponentType<P2> = null as any;

        const a = <C p={true} />;
    }
}


//// [callsOnComplexSignatures.js]
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
/// <reference path="react16.d.ts" />
var react_1 = __importDefault(require("react"));
// Simple calls from real usecases
function test1() {
    function test(t) {
        var z = t.getValue("bar"); // Should be fine
    }
}
function test2() {
    var messages = {
        foo: function (options) { return "Foo"; },
        bar: function (options) { return "Bar"; }
    };
    var test1 = function (type) {
        return messages[type]({ a: "A", b: 0 });
    };
}
function test3(items) {
    items.forEach(function (item) { return console.log(item); });
}
function test4(arg1, arg2, arg3, arg4, arg5, arg6) {
    arg1();
    arg1({ x: 0, y: 0 });
    arg1({ x: 0, y: 0 }, { x: 1, y: 1 });
    arg2({ x: 0 }, { x: 0 });
    arg3({ x: 0 });
    arg3({ x: 0 }, { x: 0, y: 0 });
    arg3({ x: 0 }, { x: 0, y: 0 }, { x: 0, y: 0 });
    arg4();
    arg4({ x: 0, y: 0 });
    arg4({ x: 0, y: 0 }, { x: 0 });
    arg5();
    arg5({ x: 0, y: 0 });
    arg5({ x: 0, y: 0 }, { x: 0 });
    arg6();
    arg6({ x: 0, y: 0 });
    arg6({ x: 0, y: 0 }, { x: 0, y: 0 });
    arg6({ x: 0, y: 0 }, { x: 0, y: 0 }, { y: 0 });
}
// JSX Tag names
function test5() {
    // Pair of non-like intrinsics
    function render(url) {
        var Tag = url ? 'a' : 'button';
        return react_1["default"].createElement(Tag, null, "test");
    }
    // Union of all intrinsics and components of `any`
    function App(props) {
        var Comp = props.component;
        return (react_1["default"].createElement(Comp, null));
    }
    // custom components with non-subset props
    function render2() {
        var C = null;
        var a = react_1["default"].createElement(C, { p: true });
    }
}