Fix typescript generator params (#9524)
* Fix typescript generator params * add TSOptionalType, TSRestType, add more test
This commit is contained in:
committed by
Nicolò Ribaudo
parent
5bb1bb080f
commit
bbb4d7b6d7
@@ -1,4 +1,4 @@
|
||||
let union: number | null | undefined;
|
||||
let intersection: number & string;
|
||||
let precedence1: number | string & boolean;
|
||||
let precedence2: number & string | boolean;
|
||||
let precedence1: number | (string & boolean);
|
||||
let precedence2: (number & string) | boolean;
|
||||
@@ -426,6 +426,40 @@ describe("programmatic generation", function() {
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("typescript generate parantheses if necessary", function() {
|
||||
it("wraps around union for array", () => {
|
||||
const typeStatement = t.TSArrayType(
|
||||
t.TSUnionType([
|
||||
t.TSIntersectionType([t.TSNumberKeyword(), t.TSBooleanKeyword()]),
|
||||
t.TSNullKeyword(),
|
||||
]),
|
||||
);
|
||||
const output = generate(typeStatement).code;
|
||||
expect(output).toBe("((number & boolean) | null)[]");
|
||||
});
|
||||
it("wraps around intersection for array", () => {
|
||||
const typeStatement = t.TSArrayType(
|
||||
t.TSIntersectionType([t.TSNumberKeyword(), t.TSBooleanKeyword()]),
|
||||
);
|
||||
const output = generate(typeStatement).code;
|
||||
expect(output).toBe("(number & boolean)[]");
|
||||
});
|
||||
it("wraps around rest", () => {
|
||||
const typeStatement = t.tsRestType(
|
||||
t.TSIntersectionType([t.TSNumberKeyword(), t.TSBooleanKeyword()]),
|
||||
);
|
||||
const output = generate(typeStatement).code;
|
||||
expect(output).toBe("...(number & boolean)");
|
||||
});
|
||||
it("wraps around optional type", () => {
|
||||
const typeStatement = t.tsOptionalType(
|
||||
t.TSIntersectionType([t.TSNumberKeyword(), t.TSBooleanKeyword()]),
|
||||
);
|
||||
const output = generate(typeStatement).code;
|
||||
expect(output).toBe("(number & boolean)?");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("CodeGenerator", function() {
|
||||
|
||||
Reference in New Issue
Block a user