Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch(typegen): stops defaultMaximumTruncationLength getter error #47

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { AppOptions } from './types'
import { Program } from 'typescript'
import { version } from '../package.json'

// The undocumented defaultMaximumTruncationLength setting determines at what point printed types are truncated.
// The undocumented defaultMaximumTruncationLength setting determines at what point printed types are truncated in versions less than 5.
// In kea-typegen output, we NEVER want the types truncated, as that results in a syntax error –
// "... n more ..." is not valid .d.ts syntax. This is a risk with union types in particular, so we disable truncation.
// See https://github.com/microsoft/TypeScript/blob/cbb8df/src/compiler/utilities.ts#L563
// and https://github.com/microsoft/TypeScript/blob/cbb8df/src/compiler/checker.ts#L6331-L6334.
(ts as any).defaultMaximumTruncationLength = Infinity
if (parseInt(ts.versionMajorMinor.split('.')[0]) < 5)) {
(ts as any).defaultMaximumTruncationLength = Infinity
}

export function runTypeGen(appOptions: AppOptions) {
let program: Program
Expand All @@ -27,6 +29,7 @@ export function runTypeGen(appOptions: AppOptions) {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
noEmit: true,
noErrorTruncation: true,
})
}
resetProgram()
Expand Down