File: contextuallyTypedStringLiteralsInJsxAttributes02.types

package info (click to toggle)
node-typescript 5.0.4%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 459,116 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (145 lines) | stat: -rw-r--r-- 5,145 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
=== tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx ===
import React = require('react')
>React : typeof React

export interface ClickableProps {
    children?: string;
>children : string

    className?: string;
>className : string
}

export interface ButtonProps extends ClickableProps {
    onClick: (k: "left" | "right") => void;
>onClick : (k: "left" | "right") => void
>k : "left" | "right"
}

export interface LinkProps extends ClickableProps {
    goTo: "home" | "contact";
>goTo : "home" | "contact"
}

export function MainButton(buttonProps: ButtonProps): JSX.Element;
>MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; }
>buttonProps : ButtonProps
>JSX : any

export function MainButton(linkProps: LinkProps): JSX.Element;
>MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; }
>linkProps : LinkProps
>JSX : any

export function MainButton(props: ButtonProps | LinkProps): JSX.Element {
>MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; }
>props : ButtonProps | LinkProps
>JSX : any

    const linkProps = props as LinkProps;
>linkProps : LinkProps
>props as LinkProps : LinkProps
>props : ButtonProps | LinkProps

    if(linkProps.goTo) {
>linkProps.goTo : "home" | "contact"
>linkProps : LinkProps
>goTo : "home" | "contact"

        return this._buildMainLink(props);
>this._buildMainLink(props) : any
>this._buildMainLink : any
>this : any
>_buildMainLink : any
>props : ButtonProps | LinkProps
    }

    return this._buildMainButton(props);
>this._buildMainButton(props) : any
>this._buildMainButton : any
>this : any
>_buildMainButton : any
>props : ButtonProps | LinkProps
}

const b0 = <MainButton {...{onClick: (k) => {console.log(k)}}} extra />;  // k has type "left" | "right"
>b0 : JSX.Element
><MainButton {...{onClick: (k) => {console.log(k)}}} extra /> : JSX.Element
>MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; }
>{onClick: (k) => {console.log(k)}} : { onClick: (k: "left" | "right") => void; }
>onClick : (k: "left" | "right") => void
>(k) => {console.log(k)} : (k: "left" | "right") => void
>k : "left" | "right"
>console.log(k) : void
>console.log : (message?: any, ...optionalParams: any[]) => void
>console : Console
>log : (message?: any, ...optionalParams: any[]) => void
>k : "left" | "right"
>extra : true

const b2 = <MainButton onClick={(k)=>{console.log(k)}} extra />;  // k has type "left" | "right"
>b2 : JSX.Element
><MainButton onClick={(k)=>{console.log(k)}} extra /> : JSX.Element
>MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; }
>onClick : (k: "left" | "right") => void
>(k)=>{console.log(k)} : (k: "left" | "right") => void
>k : "left" | "right"
>console.log(k) : void
>console.log : (message?: any, ...optionalParams: any[]) => void
>console : Console
>log : (message?: any, ...optionalParams: any[]) => void
>k : "left" | "right"
>extra : true

const b3 = <MainButton {...{goTo:"home"}} extra />;  // goTo has type"home" | "contact"
>b3 : JSX.Element
><MainButton {...{goTo:"home"}} extra /> : JSX.Element
>MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; }
>{goTo:"home"} : { goTo: "home"; }
>goTo : "home"
>"home" : "home"
>extra : true

const b4 = <MainButton goTo="home" extra />;  // goTo has type "home" | "contact"
>b4 : JSX.Element
><MainButton goTo="home" extra /> : JSX.Element
>MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; }
>goTo : "home"
>extra : true

export function NoOverload(buttonProps: ButtonProps): JSX.Element { return undefined }
>NoOverload : (buttonProps: ButtonProps) => JSX.Element
>buttonProps : ButtonProps
>JSX : any
>undefined : undefined

const c1 = <NoOverload  {...{onClick: (k) => {console.log(k)}}} extra />;  // k has type any
>c1 : JSX.Element
><NoOverload  {...{onClick: (k) => {console.log(k)}}} extra /> : JSX.Element
>NoOverload : (buttonProps: ButtonProps) => JSX.Element
>{onClick: (k) => {console.log(k)}} : { onClick: (k: "left" | "right") => void; }
>onClick : (k: "left" | "right") => void
>(k) => {console.log(k)} : (k: "left" | "right") => void
>k : "left" | "right"
>console.log(k) : void
>console.log : (message?: any, ...optionalParams: any[]) => void
>console : Console
>log : (message?: any, ...optionalParams: any[]) => void
>k : "left" | "right"
>extra : true

export function NoOverload1(linkProps: LinkProps): JSX.Element { return undefined }
>NoOverload1 : (linkProps: LinkProps) => JSX.Element
>linkProps : LinkProps
>JSX : any
>undefined : undefined

const d1 = <NoOverload1 {...{goTo:"home"}} extra  />;  // goTo has type "home" | "contact"
>d1 : JSX.Element
><NoOverload1 {...{goTo:"home"}} extra  /> : JSX.Element
>NoOverload1 : (linkProps: LinkProps) => JSX.Element
>{goTo:"home"} : { goTo: "home"; }
>goTo : "home"
>"home" : "home"
>extra : true