From 690543b857113405a592f72d70688e8621fa43a2 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Tue, 31 May 2022 19:58:30 -0600 Subject: [PATCH] Restore support for TS 4.0 through 4.5 Resolves #1945 --- .gitignore | 3 ++- CHANGELOG.md | 4 ++++ src/lib/converter/symbols.ts | 5 ++++- src/lib/types/ts-internal/index.d.ts | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 368472d53..c925ecfbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store .idea +.vs .tscache .baseDir.js .baseDir.ts @@ -22,4 +23,4 @@ src/test/renderer/specs/specs.json # Built theme JS static/main.js -/example/docs/ \ No newline at end of file +/example/docs/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 62dc53326..bde708bd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +### Bug Fixes + +- Restore support for TS 4.0 through 4.5, #1945. + ## v0.22.16 (2022-05-30) ### Features diff --git a/src/lib/converter/symbols.ts b/src/lib/converter/symbols.ts index 9e246b342..b326cc104 100644 --- a/src/lib/converter/symbols.ts +++ b/src/lib/converter/symbols.ts @@ -666,10 +666,13 @@ function convertProperty( } reflection.defaultValue = declaration && convertDefaultValue(declaration); + // FIXME: Once we drop support for TS 4.5, we can use context.checker.getTypeOfSymbol(symbol) here. reflection.type = context.converter.convertType( context, (context.isConvertingTypeNode() ? parameterType : void 0) ?? - context.checker.getTypeOfSymbol(symbol) + context.checker.getTypeOfSymbolAtLocation(symbol, { + kind: ts.SyntaxKind.SourceFile, + } as any) ); if (reflection.flags.isOptional) { diff --git a/src/lib/types/ts-internal/index.d.ts b/src/lib/types/ts-internal/index.d.ts index 76ff46700..77c5aaa88 100644 --- a/src/lib/types/ts-internal/index.d.ts +++ b/src/lib/types/ts-internal/index.d.ts @@ -21,8 +21,9 @@ declare module "typescript" { signature: ts.Signature ): ts.TypePredicate | undefined; - //https://github.com/microsoft/TypeScript/blob/v4.7.2/src/compiler/types.ts#L4188 - getTypeOfSymbol(symbol: Symbol): Type; + // Since TS 4.6, not available earlier. + // https://github.com/microsoft/TypeScript/blob/v4.7.2/src/compiler/types.ts#L4188 + // getTypeOfSymbol(symbol: Symbol): Type; } export interface Signature {