@@ -26,6 +26,42 @@ describe("transform type annotations", () => {
2626 expect ( await transform ( src ) ) . toBe ( expected ) ;
2727 } ) ;
2828
29+ it ( "Avoids marking void parameters if followed by non-optional" , async ( ) => {
30+ const src = `function f(x: void, y: string){};` ;
31+ const expected = `function f(x: undefined, y: string){};` ;
32+ expect ( await transform ( src ) ) . toBe ( expected ) ;
33+ } ) ;
34+
35+ it ( "Marks void as optional if no other parameters" , async ( ) => {
36+ const src = `function f(x: string | void, y?: string){};` ;
37+ const expected = `function f(x?: string, y?: string){};` ;
38+ expect ( await transform ( src ) ) . toBe ( expected ) ;
39+ } ) ;
40+
41+ it ( "Marks multiple void parameters optional with unions" , async ( ) => {
42+ const src = `function f(x: T | void, y: ?string){};` ;
43+ const expected = `function f(x?: T, y?: string | null){};` ;
44+ expect ( await transform ( src ) ) . toBe ( expected ) ;
45+ } ) ;
46+
47+ it ( "Avoids optionals preceding nullables" , async ( ) => {
48+ const src = `function f(x: ?T, y: string){};` ;
49+ const expected = `function f(x: T | null | undefined, y: string){};` ;
50+ expect ( await transform ( src ) ) . toBe ( expected ) ;
51+ } ) ;
52+
53+ it ( "Avoids optionals preceding non-optional unions" , async ( ) => {
54+ const src = `function f(x: T | void, y: string){};` ;
55+ const expected = `function f(x: T | undefined, y: string){};` ;
56+ expect ( await transform ( src ) ) . toBe ( expected ) ;
57+ } ) ;
58+
59+ it ( "Convertsions optional unions preceding optionals" , async ( ) => {
60+ const src = `function f(x: T | void, y?: string){};` ;
61+ const expected = `function f(x?: T, y?: string){};` ;
62+ expect ( await transform ( src ) ) . toBe ( expected ) ;
63+ } ) ;
64+
2965 it ( "Converts void types to undefined" , async ( ) => {
3066 const src = dedent `
3167 const a: string = "";
0 commit comments