|
| 1 | +package fourslash_test |
| 2 | + |
| 3 | +import ( |
| 4 | +"testing" |
| 5 | + |
| 6 | +"github.com/microsoft/typescript-go/internal/fourslash" |
| 7 | +"github.com/microsoft/typescript-go/internal/testutil" |
| 8 | +) |
| 9 | + |
| 10 | +funcTestCompletionsInJsxTagDifferentSpreadElementTypes(t*testing.T) { |
| 11 | +t.Parallel() |
| 12 | + |
| 13 | +defertestutil.RecoverAndFail(t,"Panic on fourslash test") |
| 14 | +constcontent=` |
| 15 | +// @Filename: /completionsWithDifferentSpreadTypes.tsx |
| 16 | +// @strict: true |
| 17 | +
|
| 18 | +// A reasonable type to spread. |
| 19 | +export function ComponentObjectX(props: { x: string }) { |
| 20 | + return <SomeComponent {...props} /*objectX*//>; |
| 21 | +} |
| 22 | +
|
| 23 | +// A questionable but valid type to spread. |
| 24 | +export function ComponentObjectXOrY(props: { x: string } | { y: string }) { |
| 25 | + return <SomeComponent {...props} /*objectXOrY*//>; |
| 26 | +} |
| 27 | +
|
| 28 | +// A very unexpected type to spread (a union containing a primitive). |
| 29 | +export function ComponentNumberOrObjectX(props: number | { x: string }) { |
| 30 | + return <SomeComponent {...props} /*numberOrObjectX*//>; |
| 31 | +} |
| 32 | +
|
| 33 | +// Very unexpected, but still structured (union) types. |
| 34 | +// 'boolean' is 'true | false' and an optional 'null' is really 'null | undefined'. |
| 35 | +export function ComponentBoolean(props: boolean) { |
| 36 | + return <SomeComponent {...props} /*boolean*//>; |
| 37 | +} |
| 38 | +export function ComponentOptionalNull(props?: null) { |
| 39 | + return <SomeComponent {...props} /*optNull*//>; |
| 40 | +} |
| 41 | +
|
| 42 | +// Primitive types (non-structured). |
| 43 | +export function ComponentAny(props: any) { |
| 44 | + return <SomeComponent {...props} /*any*//>; |
| 45 | +} |
| 46 | +export function ComponentUnknown(props: unknown) { |
| 47 | + return <SomeComponent {...props} /*unknown*//>; |
| 48 | +} |
| 49 | +export function ComponentNever(props: never) { |
| 50 | + return <SomeComponent {...props} /*never*//>; |
| 51 | +} |
| 52 | +export function ComponentUndefined(props: undefined) { |
| 53 | + return <SomeComponent {...props} /*undefined*//>; |
| 54 | +} |
| 55 | +export function ComponentNumber(props: number) { |
| 56 | + return <SomeComponent {...props} /*number*//>; |
| 57 | +} |
| 58 | +` |
| 59 | +f,done:=fourslash.NewFourslash(t,nil/*capabilities*/,content) |
| 60 | +deferdone() |
| 61 | +f.GoToEachMarker(t,nil,func(marker*fourslash.Marker,indexint) { |
| 62 | +f.VerifyCompletions(t,marker,nil) |
| 63 | +}) |
| 64 | +} |