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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
|
=== tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx ===
type Defaultize<TProps, TDefaults> =
>Defaultize : Defaultize<TProps, TDefaults>
& {[K in Extract<keyof TProps, keyof TDefaults>]?: TProps[K]}
& {[K in Exclude<keyof TProps, keyof TDefaults>]: TProps[K]}
& Partial<TDefaults>;
type InferredPropTypes<P> = {[K in keyof P]: P[K] extends PropTypeChecker<infer T, infer U> ? PropTypeChecker<T, U>[typeof checkedType] : {}};
>InferredPropTypes : InferredPropTypes<P>
>checkedType : unique symbol
declare const checkedType: unique symbol;
>checkedType : unique symbol
interface PropTypeChecker<U, TRequired = false> {
>false : false
(props: any, propName: string, componentName: string, location: any, propFullName: string): boolean;
>props : any
>propName : string
>componentName : string
>location : any
>propFullName : string
isRequired: PropTypeChecker<U, true>;
>isRequired : PropTypeChecker<U, true>
>true : true
[checkedType]: TRequired extends true ? U : U | null | undefined;
>[checkedType] : TRequired extends true ? U : U | null | undefined
>checkedType : unique symbol
>true : true
>null : null
}
declare namespace PropTypes {
>PropTypes : typeof PropTypes
export const number: PropTypeChecker<number>;
>number : PropTypeChecker<number, false>
export const string: PropTypeChecker<string>;
>string : PropTypeChecker<string, false>
export const node: PropTypeChecker<ReactNode>;
>node : PropTypeChecker<ReactNode, false>
}
type ReactNode = string | number | ReactComponent<{}, {}>;
>ReactNode : ReactNode
declare class ReactComponent<P={}, S={}> {
>ReactComponent : ReactComponent<P, S>
constructor(props: P);
>props : P
props: P & Readonly<{children: ReactNode[]}>;
>props : P & Readonly<{ children: ReactNode[]; }>
>children : ReactNode[]
setState(s: Partial<S>): S;
>setState : (s: Partial<S>) => S
>s : Partial<S>
render(): ReactNode;
>render : () => ReactNode
}
declare namespace JSX {
interface Element extends ReactComponent {}
interface IntrinsicElements {}
type LibraryManagedAttributes<TComponent, TProps> =
>LibraryManagedAttributes : LibraryManagedAttributes<TComponent, TProps>
TComponent extends { defaultProps: infer D; propTypes: infer P; }
>defaultProps : D
>propTypes : P
? Defaultize<TProps & InferredPropTypes<P>, D>
: TComponent extends { defaultProps: infer D }
>defaultProps : D
? Defaultize<TProps, D>
: TComponent extends { propTypes: infer P }
>propTypes : P
? TProps & InferredPropTypes<P>
: TProps;
}
class Component extends ReactComponent {
>Component : Component
>ReactComponent : ReactComponent<{}, {}>
static propTypes = {
>propTypes : { foo: PropTypeChecker<number, false>; bar: PropTypeChecker<ReactNode, false>; baz: PropTypeChecker<string, true>; }
>{ foo: PropTypes.number, bar: PropTypes.node, baz: PropTypes.string.isRequired, } : { foo: PropTypeChecker<number, false>; bar: PropTypeChecker<ReactNode, false>; baz: PropTypeChecker<string, true>; }
foo: PropTypes.number,
>foo : PropTypeChecker<number, false>
>PropTypes.number : PropTypeChecker<number, false>
>PropTypes : typeof PropTypes
>number : PropTypeChecker<number, false>
bar: PropTypes.node,
>bar : PropTypeChecker<ReactNode, false>
>PropTypes.node : PropTypeChecker<ReactNode, false>
>PropTypes : typeof PropTypes
>node : PropTypeChecker<ReactNode, false>
baz: PropTypes.string.isRequired,
>baz : PropTypeChecker<string, true>
>PropTypes.string.isRequired : PropTypeChecker<string, true>
>PropTypes.string : PropTypeChecker<string, false>
>PropTypes : typeof PropTypes
>string : PropTypeChecker<string, false>
>isRequired : PropTypeChecker<string, true>
};
static defaultProps = {
>defaultProps : { foo: number; }
>{ foo: 42, } : { foo: number; }
foo: 42,
>foo : number
>42 : 42
}
}
const a = <Component foo={12} bar="yes" baz="yeah" />;
>a : JSX.Element
><Component foo={12} bar="yes" baz="yeah" /> : JSX.Element
>Component : typeof Component
>foo : number
>12 : 12
>bar : string
>baz : string
const b = <Component foo={12} />; // Error, missing required prop bar
>b : JSX.Element
><Component foo={12} /> : JSX.Element
>Component : typeof Component
>foo : number
>12 : 12
const c = <Component bar="yes" baz="yeah" />;
>c : JSX.Element
><Component bar="yes" baz="yeah" /> : JSX.Element
>Component : typeof Component
>bar : string
>baz : string
const d = <Component bar="yes" baz="yo" bat="ohno" />; // Error, baz not a valid prop
>d : JSX.Element
><Component bar="yes" baz="yo" bat="ohno" /> : JSX.Element
>Component : typeof Component
>bar : string
>baz : string
>bat : string
const e = <Component foo={12} bar={null} baz="cool" />; // bar is nullable/undefinable since it's not marked `isRequired`
>e : JSX.Element
><Component foo={12} bar={null} baz="cool" /> : JSX.Element
>Component : typeof Component
>foo : number
>12 : 12
>bar : null
>null : null
>baz : string
const f = <Component foo={12} bar="yeah" baz={null} />; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired`
>f : JSX.Element
><Component foo={12} bar="yeah" baz={null} /> : JSX.Element
>Component : typeof Component
>foo : number
>12 : 12
>bar : string
>baz : null
>null : null
class JustPropTypes extends ReactComponent {
>JustPropTypes : JustPropTypes
>ReactComponent : ReactComponent<{}, {}>
static propTypes = {
>propTypes : { foo: PropTypeChecker<number, false>; bar: PropTypeChecker<ReactNode, true>; }
>{ foo: PropTypes.number, bar: PropTypes.node.isRequired, } : { foo: PropTypeChecker<number, false>; bar: PropTypeChecker<ReactNode, true>; }
foo: PropTypes.number,
>foo : PropTypeChecker<number, false>
>PropTypes.number : PropTypeChecker<number, false>
>PropTypes : typeof PropTypes
>number : PropTypeChecker<number, false>
bar: PropTypes.node.isRequired,
>bar : PropTypeChecker<ReactNode, true>
>PropTypes.node.isRequired : PropTypeChecker<ReactNode, true>
>PropTypes.node : PropTypeChecker<ReactNode, false>
>PropTypes : typeof PropTypes
>node : PropTypeChecker<ReactNode, false>
>isRequired : PropTypeChecker<ReactNode, true>
};
}
const g = <JustPropTypes foo={12} bar="ok" />;
>g : JSX.Element
><JustPropTypes foo={12} bar="ok" /> : JSX.Element
>JustPropTypes : typeof JustPropTypes
>foo : number
>12 : 12
>bar : string
const h = <JustPropTypes foo="no" />; // error, wrong type
>h : JSX.Element
><JustPropTypes foo="no" /> : JSX.Element
>JustPropTypes : typeof JustPropTypes
>foo : string
const i = <JustPropTypes foo={null} bar="ok" />;
>i : JSX.Element
><JustPropTypes foo={null} bar="ok" /> : JSX.Element
>JustPropTypes : typeof JustPropTypes
>foo : null
>null : null
>bar : string
const j = <JustPropTypes foo={12} bar={null} />; // error, bar is required
>j : JSX.Element
><JustPropTypes foo={12} bar={null} /> : JSX.Element
>JustPropTypes : typeof JustPropTypes
>foo : number
>12 : 12
>bar : null
>null : null
class JustDefaultProps extends ReactComponent {
>JustDefaultProps : JustDefaultProps
>ReactComponent : ReactComponent<{}, {}>
static defaultProps = {
>defaultProps : { foo: number; }
>{ foo: 42, } : { foo: number; }
foo: 42,
>foo : number
>42 : 42
};
}
const k = <JustDefaultProps foo={12} />;
>k : JSX.Element
><JustDefaultProps foo={12} /> : JSX.Element
>JustDefaultProps : typeof JustDefaultProps
>foo : number
>12 : 12
const l = <JustDefaultProps foo={12} bar="ok" />; // error, no prop named bar
>l : JSX.Element
><JustDefaultProps foo={12} bar="ok" /> : JSX.Element
>JustDefaultProps : typeof JustDefaultProps
>foo : number
>12 : 12
>bar : string
const m = <JustDefaultProps foo="no" />; // error, wrong type
>m : JSX.Element
><JustDefaultProps foo="no" /> : JSX.Element
>JustDefaultProps : typeof JustDefaultProps
>foo : string
interface FooProps {
foo: string;
>foo : string
}
class BothWithSpecifiedGeneric extends ReactComponent<FooProps> {
>BothWithSpecifiedGeneric : BothWithSpecifiedGeneric
>ReactComponent : ReactComponent<FooProps, {}>
static propTypes = {
>propTypes : { foo: PropTypeChecker<string, false>; bar: PropTypeChecker<ReactNode, false>; baz: PropTypeChecker<number, true>; }
>{ foo: PropTypes.string, bar: PropTypes.node, baz: PropTypes.number.isRequired, } : { foo: PropTypeChecker<string, false>; bar: PropTypeChecker<ReactNode, false>; baz: PropTypeChecker<number, true>; }
foo: PropTypes.string,
>foo : PropTypeChecker<string, false>
>PropTypes.string : PropTypeChecker<string, false>
>PropTypes : typeof PropTypes
>string : PropTypeChecker<string, false>
bar: PropTypes.node,
>bar : PropTypeChecker<ReactNode, false>
>PropTypes.node : PropTypeChecker<ReactNode, false>
>PropTypes : typeof PropTypes
>node : PropTypeChecker<ReactNode, false>
baz: PropTypes.number.isRequired,
>baz : PropTypeChecker<number, true>
>PropTypes.number.isRequired : PropTypeChecker<number, true>
>PropTypes.number : PropTypeChecker<number, false>
>PropTypes : typeof PropTypes
>number : PropTypeChecker<number, false>
>isRequired : PropTypeChecker<number, true>
};
static defaultProps = {
>defaultProps : { foo: string; }
>{ foo: "yo", } : { foo: string; }
foo: "yo",
>foo : string
>"yo" : "yo"
};
}
const n = <BothWithSpecifiedGeneric foo="fine" bar="yes" baz={12} />;
>n : JSX.Element
><BothWithSpecifiedGeneric foo="fine" bar="yes" baz={12} /> : JSX.Element
>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric
>foo : string
>bar : string
>baz : number
>12 : 12
const o = <BothWithSpecifiedGeneric foo="no" />; // Error, missing required prop bar
>o : JSX.Element
><BothWithSpecifiedGeneric foo="no" /> : JSX.Element
>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric
>foo : string
const p = <BothWithSpecifiedGeneric bar="yes" baz={12} />;
>p : JSX.Element
><BothWithSpecifiedGeneric bar="yes" baz={12} /> : JSX.Element
>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric
>bar : string
>baz : number
>12 : 12
const q = <BothWithSpecifiedGeneric bar="yes" baz={12} bat="ohno" />; // Error, baz not a valid prop
>q : JSX.Element
><BothWithSpecifiedGeneric bar="yes" baz={12} bat="ohno" /> : JSX.Element
>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric
>bar : string
>baz : number
>12 : 12
>bat : string
const r = <BothWithSpecifiedGeneric foo="no" bar={null} baz={0} />; // bar is nullable/undefinable since it's not marked `isRequired`
>r : JSX.Element
><BothWithSpecifiedGeneric foo="no" bar={null} baz={0} /> : JSX.Element
>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric
>foo : string
>bar : null
>null : null
>baz : number
>0 : 0
const s = <BothWithSpecifiedGeneric foo="eh" bar="yeah" baz={null} />; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired`
>s : JSX.Element
><BothWithSpecifiedGeneric foo="eh" bar="yeah" baz={null} /> : JSX.Element
>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric
>foo : string
>bar : string
>baz : null
>null : null
class JustPropTypesWithSpecifiedGeneric extends ReactComponent<FooProps> {
>JustPropTypesWithSpecifiedGeneric : JustPropTypesWithSpecifiedGeneric
>ReactComponent : ReactComponent<FooProps, {}>
static propTypes = {
>propTypes : { foo: PropTypeChecker<string, false>; bar: PropTypeChecker<ReactNode, true>; }
>{ foo: PropTypes.string, bar: PropTypes.node.isRequired, } : { foo: PropTypeChecker<string, false>; bar: PropTypeChecker<ReactNode, true>; }
foo: PropTypes.string,
>foo : PropTypeChecker<string, false>
>PropTypes.string : PropTypeChecker<string, false>
>PropTypes : typeof PropTypes
>string : PropTypeChecker<string, false>
bar: PropTypes.node.isRequired,
>bar : PropTypeChecker<ReactNode, true>
>PropTypes.node.isRequired : PropTypeChecker<ReactNode, true>
>PropTypes.node : PropTypeChecker<ReactNode, false>
>PropTypes : typeof PropTypes
>node : PropTypeChecker<ReactNode, false>
>isRequired : PropTypeChecker<ReactNode, true>
};
}
const t = <JustPropTypesWithSpecifiedGeneric foo="nice" bar="ok" />;
>t : JSX.Element
><JustPropTypesWithSpecifiedGeneric foo="nice" bar="ok" /> : JSX.Element
>JustPropTypesWithSpecifiedGeneric : typeof JustPropTypesWithSpecifiedGeneric
>foo : string
>bar : string
const u = <JustPropTypesWithSpecifiedGeneric foo={12} />; // error, wrong type
>u : JSX.Element
><JustPropTypesWithSpecifiedGeneric foo={12} /> : JSX.Element
>JustPropTypesWithSpecifiedGeneric : typeof JustPropTypesWithSpecifiedGeneric
>foo : number
>12 : 12
const v = <JustPropTypesWithSpecifiedGeneric foo={null} bar="ok" />; // generic overrides propTypes required-ness, null isn't valid
>v : JSX.Element
><JustPropTypesWithSpecifiedGeneric foo={null} bar="ok" /> : JSX.Element
>JustPropTypesWithSpecifiedGeneric : typeof JustPropTypesWithSpecifiedGeneric
>foo : null
>null : null
>bar : string
const w = <JustPropTypesWithSpecifiedGeneric foo="cool" bar={null} />; // error, bar is required
>w : JSX.Element
><JustPropTypesWithSpecifiedGeneric foo="cool" bar={null} /> : JSX.Element
>JustPropTypesWithSpecifiedGeneric : typeof JustPropTypesWithSpecifiedGeneric
>foo : string
>bar : null
>null : null
class JustDefaultPropsWithSpecifiedGeneric extends ReactComponent<FooProps> {
>JustDefaultPropsWithSpecifiedGeneric : JustDefaultPropsWithSpecifiedGeneric
>ReactComponent : ReactComponent<FooProps, {}>
static defaultProps = {
>defaultProps : { foo: string; }
>{ foo: "no", } : { foo: string; }
foo: "no",
>foo : string
>"no" : "no"
};
}
const x = <JustDefaultPropsWithSpecifiedGeneric foo="eh" />;
>x : JSX.Element
><JustDefaultPropsWithSpecifiedGeneric foo="eh" /> : JSX.Element
>JustDefaultPropsWithSpecifiedGeneric : typeof JustDefaultPropsWithSpecifiedGeneric
>foo : string
const y = <JustDefaultPropsWithSpecifiedGeneric foo="no" bar="ok" />; // error, no prop named bar
>y : JSX.Element
><JustDefaultPropsWithSpecifiedGeneric foo="no" bar="ok" /> : JSX.Element
>JustDefaultPropsWithSpecifiedGeneric : typeof JustDefaultPropsWithSpecifiedGeneric
>foo : string
>bar : string
const z = <JustDefaultPropsWithSpecifiedGeneric foo={12} />; // error, wrong type
>z : JSX.Element
><JustDefaultPropsWithSpecifiedGeneric foo={12} /> : JSX.Element
>JustDefaultPropsWithSpecifiedGeneric : typeof JustDefaultPropsWithSpecifiedGeneric
>foo : number
>12 : 12
const aa = <JustDefaultPropsWithSpecifiedGeneric />;
>aa : JSX.Element
><JustDefaultPropsWithSpecifiedGeneric /> : JSX.Element
>JustDefaultPropsWithSpecifiedGeneric : typeof JustDefaultPropsWithSpecifiedGeneric
|