diff --git a/src/typescript/codeGeneration.ts b/src/typescript/codeGeneration.ts index e485fa346e..474fffd2b3 100644 --- a/src/typescript/codeGeneration.ts +++ b/src/typescript/codeGeneration.ts @@ -73,11 +73,10 @@ function enumerationDeclaration(generator: CodeGenerator, type: GraphQLEnumType) generator.printOnNewline(`// ${line.trim()}`); }) } - generator.printOnNewline(`export type ${name} =`); - const nValues = values.length; - values.forEach((value, i) => { + generator.printOnNewline(`export enum ${name} {`); + values.forEach((value) => { if (!value.description || value.description.indexOf('\n') === -1) { - generator.printOnNewline(` "${value.value}"${i === nValues - 1 ? ';' : ' |'}${wrap(' // ', value.description)}`) + generator.printOnNewline(` ${value.value} = "${value.value}",${wrap(' // ', value.description)}`) } else { if (value.description) { value.description.split('\n') @@ -85,9 +84,10 @@ function enumerationDeclaration(generator: CodeGenerator, type: GraphQLEnumType) generator.printOnNewline(` // ${line.trim()}`); }) } - generator.printOnNewline(` "${value.value}"${i === nValues - 1 ? ';' : ' |'}`) + generator.printOnNewline(` ${value.value} = "${value.value}",`) } }); + generator.printOnNewline(`}`); generator.printNewline(); } diff --git a/test/typescript/__snapshots__/codeGeneration.js.snap b/test/typescript/__snapshots__/codeGeneration.js.snap index bce3b60efe..677e76638d 100644 --- a/test/typescript/__snapshots__/codeGeneration.js.snap +++ b/test/typescript/__snapshots__/codeGeneration.js.snap @@ -5,10 +5,11 @@ exports[`TypeScript code generation #generateSource() should generate correct li // This file was automatically generated and should not be edited. // The episodes in the Star Wars trilogy -export type Episode = - \\"NEWHOPE\\" | // Star Wars Episode IV: A New Hope, released in 1977. - \\"EMPIRE\\" | // Star Wars Episode V: The Empire Strikes Back, released in 1980. - \\"JEDI\\"; // Star Wars Episode VI: Return of the Jedi, released in 1983. +export enum Episode { + NEWHOPE = \\"NEWHOPE\\", // Star Wars Episode IV: A New Hope, released in 1977. + EMPIRE = \\"EMPIRE\\", // Star Wars Episode V: The Empire Strikes Back, released in 1980. + JEDI = \\"JEDI\\", // Star Wars Episode VI: Return of the Jedi, released in 1983. +} export type HeroAndFriendsNamesQueryVariables = { @@ -140,10 +141,11 @@ exports[`TypeScript code generation #generateSource() should generate mutation o // This file was automatically generated and should not be edited. // The episodes in the Star Wars trilogy -export type Episode = - \\"NEWHOPE\\" | // Star Wars Episode IV: A New Hope, released in 1977. - \\"EMPIRE\\" | // Star Wars Episode V: The Empire Strikes Back, released in 1980. - \\"JEDI\\"; // Star Wars Episode VI: Return of the Jedi, released in 1983. +export enum Episode { + NEWHOPE = \\"NEWHOPE\\", // Star Wars Episode IV: A New Hope, released in 1977. + EMPIRE = \\"EMPIRE\\", // Star Wars Episode V: The Empire Strikes Back, released in 1980. + JEDI = \\"JEDI\\", // Star Wars Episode VI: Return of the Jedi, released in 1983. +} export type ReviewInput = { @@ -219,10 +221,11 @@ exports[`TypeScript code generation #generateSource() should generate simple nes // This file was automatically generated and should not be edited. // The episodes in the Star Wars trilogy -export type Episode = - \\"NEWHOPE\\" | // Star Wars Episode IV: A New Hope, released in 1977. - \\"EMPIRE\\" | // Star Wars Episode V: The Empire Strikes Back, released in 1980. - \\"JEDI\\"; // Star Wars Episode VI: Return of the Jedi, released in 1983. +export enum Episode { + NEWHOPE = \\"NEWHOPE\\", // Star Wars Episode IV: A New Hope, released in 1977. + EMPIRE = \\"EMPIRE\\", // Star Wars Episode V: The Empire Strikes Back, released in 1980. + JEDI = \\"JEDI\\", // Star Wars Episode VI: Return of the Jedi, released in 1983. +} export type HeroAndFriendsNamesQueryVariables = { @@ -306,10 +309,11 @@ exports[`TypeScript code generation #generateSource() should generate simple que // This file was automatically generated and should not be edited. // The episodes in the Star Wars trilogy -export type Episode = - \\"NEWHOPE\\" | // Star Wars Episode IV: A New Hope, released in 1977. - \\"EMPIRE\\" | // Star Wars Episode V: The Empire Strikes Back, released in 1980. - \\"JEDI\\"; // Star Wars Episode VI: Return of the Jedi, released in 1983. +export enum Episode { + NEWHOPE = \\"NEWHOPE\\", // Star Wars Episode IV: A New Hope, released in 1977. + EMPIRE = \\"EMPIRE\\", // Star Wars Episode V: The Empire Strikes Back, released in 1980. + JEDI = \\"JEDI\\", // Star Wars Episode VI: Return of the Jedi, released in 1983. +} export type HeroNameQueryVariables = { @@ -336,11 +340,12 @@ exports[`TypeScript code generation #generateSource() should handle comments in "/* tslint:disable */ // This file was automatically generated and should not be edited. -export type EnumCommentTestCase = - \\"first\\" | // This is a single-line comment +export enum EnumCommentTestCase { + first = \\"first\\", // This is a single-line comment // This is a multi-line // comment. - \\"second\\"; + second = \\"second\\", +} export type CustomScalarQuery = {