diff --git a/src/printer.js b/src/printer.js index b3afc61f5..fe9cc3dc9 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1515,8 +1515,10 @@ function genericPrintNoParens(path, options, print, args) { path.getParentNode().constraint) && // TypeScript should not have a colon in TSFirstTypeNode nodes // `a is number` + // or TSConstructorType nodes !(path.getParentNode().type === "TypeAnnotation" && - path.getParentNode().typeAnnotation.type === 'TSFirstTypeNode') + (path.getParentNode().typeAnnotation.type === 'TSFirstTypeNode' || + path.getParentNode().typeAnnotation.type === "TSConstructorType")) ) { parts.push(": "); } @@ -1972,6 +1974,13 @@ function genericPrintNoParens(path, options, print, args) { path.call(print, "indexType"), "]" ]) + case "TSConstructorType": + return concat([ + "new(", + join(", ", path.map(print, "parameters")), + ") => ", + path.call(print, "typeAnnotation"), + ]) // TODO case "ClassHeritage": // TODO diff --git a/tests/typescript/conformance/types/constructorType/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/conformance/types/constructorType/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..3961f1fac --- /dev/null +++ b/tests/typescript/conformance/types/constructorType/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`cunstructorType.ts 1`] = ` +var d: new(x: number) => void; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +var d: new(x: number) => void; + +`; diff --git a/tests/typescript/conformance/types/constructorType/cunstructorType.ts b/tests/typescript/conformance/types/constructorType/cunstructorType.ts new file mode 100644 index 000000000..2308d1d36 --- /dev/null +++ b/tests/typescript/conformance/types/constructorType/cunstructorType.ts @@ -0,0 +1 @@ +var d: new(x: number) => void; diff --git a/tests/typescript/conformance/types/constructorType/jsfmt.spec.js b/tests/typescript/conformance/types/constructorType/jsfmt.spec.js new file mode 100644 index 000000000..bc085c48c --- /dev/null +++ b/tests/typescript/conformance/types/constructorType/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "typescript" });