File tree Expand file tree Collapse file tree
tests/cases/conformance/types/contextualTypes/jsxAttributes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // @filename : file.tsx
2+ // @jsx : preserve
3+ // @module : amd
4+ // @noLib : true
5+ // @libFiles : react.d.ts,lib.d.ts
6+
7+ import React = require( 'react' )
8+
9+ export interface ClickableProps {
10+ children ?: string ;
11+ className ?: string ;
12+ }
13+
14+ export interface ButtonProps extends ClickableProps {
15+ onClick : ( k : "left" | "right" ) => void ;
16+ }
17+
18+ export interface LinkProps extends ClickableProps {
19+ goTo : "home" | "contact" ;
20+ }
21+
22+ export function MainButton ( buttonProps : ButtonProps ) : JSX . Element ;
23+ export function MainButton ( linkProps : LinkProps ) : JSX . Element ;
24+ export function MainButton ( props : ButtonProps | LinkProps ) : JSX . Element {
25+ const linkProps = props as LinkProps ;
26+ if ( linkProps . goTo ) {
27+ return this . _buildMainLink ( props ) ;
28+ }
29+
30+ return this . _buildMainButton ( props ) ;
31+ }
32+
33+ const b0 = < MainButton { ...{ onClick : ( k ) => { console . log ( k ) } } } extra /> ; // k has type any
34+ const b2 = < MainButton onClick = { ( k ) => { console . log ( k ) } } extra /> ; // k has type "left" | "right"
35+ const b3 = < MainButton { ...{ goTo :"home" } } extra /> ; // goTo has type"home" | "contact"
36+ const b4 = < MainButton goTo = "home" extra /> ; // goTo has type "home" | "contact"
37+
38+ export function NoOverload ( buttonProps : ButtonProps ) : JSX . Element { return undefined }
39+ const c1 = < NoOverload { ...{ onClick : ( k ) => { console . log ( k ) } } } extra /> ; // k has type any
40+
41+ export function NoOverload1 ( linkProps : LinkProps ) : JSX . Element { return undefined }
42+ const d1 = < NoOverload1 { ...{ goTo :"home" } } extra /> ; // goTo has type "home" | "contact"
You can’t perform that action at this time.
0 commit comments