Skip to content

Commit ee27362

Browse files
committed
feat: Support for TypeScript 4.2
Resolves TypeStrong#1517
1 parent d486244 commit ee27362

29 files changed

+941
-701
lines changed

examples/basic/src/classes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,6 @@ export class GenericClass<T extends BaseClass> {
321321
* This a non generic class derived from a [[GenericClass|generic class]].
322322
*/
323323
export class NonGenericClass extends GenericClass<SubClassB> {}
324+
325+
// TS 4.2
326+
export type AbstractMe = abstract new () => NonGenericClass

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
"progress": "^2.0.3",
3131
"shelljs": "^0.8.4",
3232
"shiki": "^0.9.2",
33-
"typedoc-default-themes": "^0.12.7"
33+
"typedoc-default-themes": "^0.12.8"
3434
},
3535
"peerDependencies": {
36-
"typescript": "3.9.x || 4.0.x || 4.1.x"
36+
"typescript": "3.9.x || 4.0.x || 4.1.x || 4.2.x"
3737
},
3838
"devDependencies": {
3939
"@types/fs-extra": "^9.0.7",
@@ -53,7 +53,7 @@
5353
"mockery": "^2.1.0",
5454
"nyc": "^15.1.0",
5555
"prettier": "^2.2.1",
56-
"typescript": "^4.1.5"
56+
"typescript": "^4.2.2"
5757
},
5858
"files": [
5959
"bin",

src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ export { UrlMapping } from "./lib/output/models/UrlMapping";
1616
export {
1717
BindOption,
1818
Options,
19-
OptionsReader,
2019
ParameterHint,
2120
ParameterType,
22-
TypeDocOptions,
23-
TypeDocOptionMap,
24-
KeyToDeclaration,
2521
TSConfigReader,
2622
TypeDocReader,
2723
ArgumentsReader,
24+
} from "./lib/utils/options";
25+
26+
export type {
27+
OptionsReader,
28+
TypeDocOptions,
29+
TypeDocOptionMap,
30+
KeyToDeclaration,
2831
DeclarationOption,
2932
DeclarationOptionBase,
3033
StringDeclarationOption,

src/lib/converter/types.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
UnknownType,
2323
MappedType,
2424
SignatureReflection,
25+
ReflectionFlag,
2526
} from "../models";
2627
import { OptionalType } from "../models/types/optional";
2728
import { RestType } from "../models/types/rest";
@@ -103,7 +104,7 @@ const seenTypeSymbols = new Set<ts.Symbol>();
103104
export function convertType(
104105
context: Context,
105106
typeOrNode: ts.Type | ts.TypeNode | undefined
106-
) {
107+
): Type {
107108
if (!typeOrNode) {
108109
return new IntrinsicType("any");
109110
}
@@ -117,6 +118,11 @@ export function convertType(
117118
return requestBugReport(context, typeOrNode);
118119
}
119120

121+
// TS 4.2 added this to enable better tracking of type aliases.
122+
if (typeOrNode.isUnion() && typeOrNode.origin) {
123+
return convertType(context, typeOrNode.origin);
124+
}
125+
120126
// IgnoreErrors is important, without it, we can't assert that we will get a node.
121127
const node = context.checker.typeToTypeNode(
122128
typeOrNode,
@@ -213,6 +219,16 @@ const constructorConverter: TypeConverter<ts.ConstructorTypeNode, ts.Type> = {
213219
ReflectionKind.ConstructorSignature,
214220
reflection
215221
);
222+
// This is unfortunate... but seems the obvious place to put this with the current
223+
// architecture. Ideally, this would be a property on a "ConstructorType"... but that
224+
// needs to wait until TypeDoc 0.22 when making other breaking changes.
225+
if (
226+
node.modifiers?.some(
227+
(m) => m.kind === ts.SyntaxKind.AbstractKeyword
228+
)
229+
) {
230+
signature.setFlag(ReflectionFlag.Abstract);
231+
}
216232
context.registerReflection(signature, void 0);
217233
const signatureCtx = rc.withScope(signature);
218234

src/lib/models/reflections/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ export {
22
Reflection,
33
ReflectionKind,
44
ReflectionFlag,
5-
TypeParameterContainer,
6-
Decorator,
75
TraverseProperty,
86
ReflectionFlags,
97
} from "./abstract";
8+
export type { TypeParameterContainer, Decorator } from "./abstract";
109
export { ContainerReflection } from "./container";
11-
export { DeclarationReflection, DeclarationHierarchy } from "./declaration";
10+
export { DeclarationReflection } from "./declaration";
11+
export type { DeclarationHierarchy } from "./declaration";
1212
export { ParameterReflection } from "./parameter";
1313
export { ProjectReflection } from "./project";
1414
export { ReferenceReflection } from "./reference";

src/lib/models/sources/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { SourceDirectory } from "./directory";
2-
export { SourceFile, SourceReference } from "./file";
2+
export { SourceFile } from "./file";
3+
export type { SourceReference } from "./file";

src/lib/ts-internal.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ declare module "typescript" {
2222
): ts.TypePredicate | undefined;
2323
}
2424

25+
// https://github.com/microsoft/TypeScript/blob/e213b2af3430bdc9cf5fbc76a8634d832e7aaaaa/src/compiler/types.ts#L5298-L5299
26+
export interface UnionType {
27+
/* @internal */
28+
origin?: ts.Type; // Denormalized union, intersection, or index type in which union originates
29+
}
30+
2531
// https://github.com/microsoft/TypeScript/blob/v4.1.5/src/compiler/types.ts#L4707-L4732
2632
/* @internal */
27-
export const enum CheckFlags {
33+
export enum CheckFlags {
2834
Instantiated = 1 << 0, // Instantiated symbol
2935
SyntheticProperty = 1 << 1, // Property in union or intersection type
3036
SyntheticMethod = 1 << 2, // Method in union or intersection type

src/lib/utils/options/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
export { Options, OptionsReader, BindOption } from "./options";
1+
export { Options, BindOption } from "./options";
2+
export type { OptionsReader } from "./options";
23
export { ArgumentsReader, TypeDocReader, TSConfigReader } from "./readers";
3-
export {
4+
export { ParameterType, ParameterHint } from "./declaration";
5+
6+
export type {
47
TypeDocOptions,
58
TypeDocOptionMap,
69
KeyToDeclaration,
7-
ParameterType,
8-
ParameterHint,
910
DeclarationOption,
1011
DeclarationOptionBase,
1112
StringDeclarationOption,

src/test/converter/class/class.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,10 @@ export namespace GH1509 {
130130
export interface PartialFoo extends Partial<Foo> {}
131131
export interface ReadonlyFoo extends Readonly<Partial<Foo>> {}
132132
}
133+
134+
export abstract class Abstract {
135+
abstract needsImpl(): number
136+
}
137+
138+
// TS 4.2
139+
export type AbstractMe = abstract new () => Abstract

0 commit comments

Comments
 (0)