forked from joarwilk/flowgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for spread operator when intersecting types
- Loading branch information
1 parent
f90d513
commit 3f0622c
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should not insert spread when performing union of class types 1`] = ` | ||
"declare class Foo {} | ||
declare class Bar {} | ||
declare var combination: Foo & Bar; | ||
" | ||
`; | ||
|
||
exports[`should use spread when performing union of object types 1`] = ` | ||
"declare type Foo = { | ||
foo: number, | ||
... | ||
}; | ||
declare type Bar = { | ||
bar: string, | ||
... | ||
}; | ||
declare var combination: { ...Foo, ...Bar }; | ||
" | ||
`; | ||
|
||
exports[`should use spread when performing union of object types 2`] = ` | ||
"declare type Foo = {| | ||
foo: number, | ||
|}; | ||
declare type Bar = {| | ||
bar: string, | ||
|}; | ||
declare var combination: {| ...Foo, ...Bar |}; | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { compiler, beautify } from ".."; | ||
import "../test-matchers"; | ||
|
||
it("should use spread when performing union of object types", () => { | ||
const ts = ` | ||
type Foo = { foo: number }; | ||
type Bar = { bar: string }; | ||
const combination: Foo & Bar; | ||
`; | ||
|
||
{ | ||
const result = compiler.compileDefinitionString(ts, { quiet: true }); | ||
expect(beautify(result)).toMatchSnapshot(); | ||
expect(result).toBeValidFlowTypeDeclarations(); | ||
} | ||
|
||
{ | ||
const result = compiler.compileDefinitionString(ts, { quiet: true, inexact: false }); | ||
expect(beautify(result)).toMatchSnapshot(); | ||
expect(result).toBeValidFlowTypeDeclarations(); | ||
} | ||
}); | ||
|
||
|
||
it("should not insert spread when performing union of class types", () => { | ||
const ts = ` | ||
class Foo {} | ||
class Bar {} | ||
const combination: Foo & Bar; | ||
`; | ||
const result = compiler.compileDefinitionString(ts, { quiet: true }); | ||
expect(beautify(result)).toMatchSnapshot(); | ||
expect(result).toBeValidFlowTypeDeclarations(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters