Skip to content

Commit

Permalink
feat: Support for TypeScript 4.2
Browse files Browse the repository at this point in the history
Resolves #1517
  • Loading branch information
Gerrit0 committed Mar 4, 2021
1 parent d486244 commit ee27362
Show file tree
Hide file tree
Showing 29 changed files with 941 additions and 701 deletions.
3 changes: 3 additions & 0 deletions examples/basic/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,6 @@ export class GenericClass<T extends BaseClass> {
* This a non generic class derived from a [[GenericClass|generic class]].
*/
export class NonGenericClass extends GenericClass<SubClassB> {}

// TS 4.2
export type AbstractMe = abstract new () => NonGenericClass
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"progress": "^2.0.3",
"shelljs": "^0.8.4",
"shiki": "^0.9.2",
"typedoc-default-themes": "^0.12.7"
"typedoc-default-themes": "^0.12.8"
},
"peerDependencies": {
"typescript": "3.9.x || 4.0.x || 4.1.x"
"typescript": "3.9.x || 4.0.x || 4.1.x || 4.2.x"
},
"devDependencies": {
"@types/fs-extra": "^9.0.7",
Expand All @@ -53,7 +53,7 @@
"mockery": "^2.1.0",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"typescript": "^4.1.5"
"typescript": "^4.2.2"
},
"files": [
"bin",
Expand Down
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ export { UrlMapping } from "./lib/output/models/UrlMapping";
export {
BindOption,
Options,
OptionsReader,
ParameterHint,
ParameterType,
TypeDocOptions,
TypeDocOptionMap,
KeyToDeclaration,
TSConfigReader,
TypeDocReader,
ArgumentsReader,
} from "./lib/utils/options";

export type {
OptionsReader,
TypeDocOptions,
TypeDocOptionMap,
KeyToDeclaration,
DeclarationOption,
DeclarationOptionBase,
StringDeclarationOption,
Expand Down
18 changes: 17 additions & 1 deletion src/lib/converter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
UnknownType,
MappedType,
SignatureReflection,
ReflectionFlag,
} from "../models";
import { OptionalType } from "../models/types/optional";
import { RestType } from "../models/types/rest";
Expand Down Expand Up @@ -103,7 +104,7 @@ const seenTypeSymbols = new Set<ts.Symbol>();
export function convertType(
context: Context,
typeOrNode: ts.Type | ts.TypeNode | undefined
) {
): Type {
if (!typeOrNode) {
return new IntrinsicType("any");
}
Expand All @@ -117,6 +118,11 @@ export function convertType(
return requestBugReport(context, typeOrNode);
}

// TS 4.2 added this to enable better tracking of type aliases.
if (typeOrNode.isUnion() && typeOrNode.origin) {
return convertType(context, typeOrNode.origin);
}

// IgnoreErrors is important, without it, we can't assert that we will get a node.
const node = context.checker.typeToTypeNode(
typeOrNode,
Expand Down Expand Up @@ -213,6 +219,16 @@ const constructorConverter: TypeConverter<ts.ConstructorTypeNode, ts.Type> = {
ReflectionKind.ConstructorSignature,
reflection
);
// This is unfortunate... but seems the obvious place to put this with the current
// architecture. Ideally, this would be a property on a "ConstructorType"... but that
// needs to wait until TypeDoc 0.22 when making other breaking changes.
if (
node.modifiers?.some(
(m) => m.kind === ts.SyntaxKind.AbstractKeyword
)
) {
signature.setFlag(ReflectionFlag.Abstract);
}
context.registerReflection(signature, void 0);
const signatureCtx = rc.withScope(signature);

Expand Down
6 changes: 3 additions & 3 deletions src/lib/models/reflections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ export {
Reflection,
ReflectionKind,
ReflectionFlag,
TypeParameterContainer,
Decorator,
TraverseProperty,
ReflectionFlags,
} from "./abstract";
export type { TypeParameterContainer, Decorator } from "./abstract";
export { ContainerReflection } from "./container";
export { DeclarationReflection, DeclarationHierarchy } from "./declaration";
export { DeclarationReflection } from "./declaration";
export type { DeclarationHierarchy } from "./declaration";
export { ParameterReflection } from "./parameter";
export { ProjectReflection } from "./project";
export { ReferenceReflection } from "./reference";
Expand Down
3 changes: 2 additions & 1 deletion src/lib/models/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { SourceDirectory } from "./directory";
export { SourceFile, SourceReference } from "./file";
export { SourceFile } from "./file";
export type { SourceReference } from "./file";
8 changes: 7 additions & 1 deletion src/lib/ts-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ declare module "typescript" {
): ts.TypePredicate | undefined;
}

// https://github.com/microsoft/TypeScript/blob/e213b2af3430bdc9cf5fbc76a8634d832e7aaaaa/src/compiler/types.ts#L5298-L5299
export interface UnionType {
/* @internal */
origin?: ts.Type; // Denormalized union, intersection, or index type in which union originates
}

// https://github.com/microsoft/TypeScript/blob/v4.1.5/src/compiler/types.ts#L4707-L4732
/* @internal */
export const enum CheckFlags {
export enum CheckFlags {
Instantiated = 1 << 0, // Instantiated symbol
SyntheticProperty = 1 << 1, // Property in union or intersection type
SyntheticMethod = 1 << 2, // Method in union or intersection type
Expand Down
9 changes: 5 additions & 4 deletions src/lib/utils/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export { Options, OptionsReader, BindOption } from "./options";
export { Options, BindOption } from "./options";
export type { OptionsReader } from "./options";
export { ArgumentsReader, TypeDocReader, TSConfigReader } from "./readers";
export {
export { ParameterType, ParameterHint } from "./declaration";

export type {
TypeDocOptions,
TypeDocOptionMap,
KeyToDeclaration,
ParameterType,
ParameterHint,
DeclarationOption,
DeclarationOptionBase,
StringDeclarationOption,
Expand Down
7 changes: 7 additions & 0 deletions src/test/converter/class/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,10 @@ export namespace GH1509 {
export interface PartialFoo extends Partial<Foo> {}
export interface ReadonlyFoo extends Readonly<Partial<Foo>> {}
}

export abstract class Abstract {
abstract needsImpl(): number
}

// TS 4.2
export type AbstractMe = abstract new () => Abstract
Loading

0 comments on commit ee27362

Please sign in to comment.