From d2eb7bd9de8ed258eb2a4be3825760efeec467e9 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Thu, 28 Oct 2021 19:38:50 +0300 Subject: [PATCH] version: force proper typing on version literals Types should be generic and stay the same across different versions E.g. `preReleaseTag` should be typed `string | null` even if it's a `null` literal for this particular release --- resources/gen-version.js | 12 +++++++----- src/version.ts | 10 +++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/resources/gen-version.js b/resources/gen-version.js index e4219d5cf5..944b51401d 100644 --- a/resources/gen-version.js +++ b/resources/gen-version.js @@ -18,16 +18,18 @@ const body = ` /** * A string containing the version of the GraphQL.js library */ -export const version = '${version}'; +export const version = '${version}' as string; /** * An object containing the components of the GraphQL.js version string */ export const versionInfo = Object.freeze({ - major: ${major}, - minor: ${minor}, - patch: ${patch}, - preReleaseTag: ${preReleaseTag ? `'${preReleaseTag}'` : 'null'}, + major: ${major} as number, + minor: ${minor} as number, + patch: ${patch} as number, + preReleaseTag: ${ + preReleaseTag ? `'${preReleaseTag}'` : 'null' + } as string | null, }); `; diff --git a/src/version.ts b/src/version.ts index 8adb01a97c..971122bc7c 100644 --- a/src/version.ts +++ b/src/version.ts @@ -4,14 +4,14 @@ /** * A string containing the version of the GraphQL.js library */ -export const version = '16.0.0-rc.7'; +export const version = '16.0.0-rc.7' as string; /** * An object containing the components of the GraphQL.js version string */ export const versionInfo = Object.freeze({ - major: 16, - minor: 0, - patch: 0, - preReleaseTag: 'rc.7', + major: 16 as number, + minor: 0 as number, + patch: 0 as number, + preReleaseTag: 'rc.7' as string | null, });