//@flow import * as React from 'react'; component InlineOnly(foo: number, bar: string) { return null; } const inlineOnlyGood = ; // OK! const inlineOnlyBad = ; // Error 2x component InexactRest(foo: number, ...rest: {bar: string, ...}) { return null; } const inexactGood = ; // OK! const inexactBad = ; // ERROR 2x for foo and bar component IndexedRest(foo: number, ...rest: {[key: string]: number, ...}) { return null; } const indexedGood = ; // OK! const indexedBad = ; // ERROR 2x for foo and bar component DefaultProps(foo: number = 3) { return null; } const defaultsGood = ; // OK! const defaultsBad = ; // ERROR component RenamedParams( foo as bar: number, bar as foo: string, 'non-ident' as baz: string, ) { return
; } const renamedGood = ; // OK! const renamedWrongProps = ; // ERROR 4x, bad foo type, bad bar type, no non-ident, extra baz component HasOptionalParams( x?: number, y: number = 3, ...rest?: {foo: number} // ERROR, rest params can't be optional ) { x as number; // ERROR y as number; // OK! rest as {foo: number}; // ERROR, rest is optional in the body, as typed return; } const elNoArgs = ; const elOnlyX = ; const elOnlyY = ; const elBoth = ; component Destruct(foo: number, ...{bar}: {bar: number}) { return null; } ; component OptionalAsBinding( foo as bar?: number, ) { bar as number; // ERROR, bar is optional bar as number | void; // OK return; } ; ; ; // ERROR component OptionalStringKeyAsBinding( 'aria-label' as ariaLabel?: string, ) { ariaLabel as string; // ERROR, ariaLabel is optional ariaLabel as string | void; // OK return; } ; ; ; // ERROR module.exports = { InlineOnly, InexactRest, IndexedRest, DefaultProps, RenamedParams, Destruct, OptionalAsBinding, OptionalStringKeyAsBinding, };