-
-
Notifications
You must be signed in to change notification settings - Fork 735
Use npm @types/*
for 3rd party type definitions
#310
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
Changes from all commits
52a4956
a573370
ed77b41
37db93e
9491132
99ab42b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import * as ts from "typescript"; | ||
|
||
/** | ||
* Expose the internal TypeScript APIs that are used by TypeDoc | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 to identifying the internal APIs so we can move off of them. Way to also link to the internal TS definitions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any concern about the out-datedness that could occur here? Is there a way to build it with the internal APIs exposed instead and use that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is certainly a concern. My hope is that these internal usages can be replaced by other APIs. |
||
declare module "typescript" { | ||
interface Symbol { | ||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L2166 | ||
id?: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can expose a getter on the Symbol class to expose this as needed. please file an issue for it. |
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L2168 | ||
parent?: ts.Symbol; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can expose this. please file an issue for it. |
||
} | ||
|
||
interface Node { | ||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L469 | ||
symbol?: ts.Symbol; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L472 | ||
localSymbol?: ts.Symbol; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not think you should ever use this. it is misleading, and very subtle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I used this to get the local name of a default export |
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L471 | ||
nextContainer?: ts.Node; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not use this. there are better ways to accomplish what you want. |
||
} | ||
|
||
/** | ||
* These functions are in "core" and are marked as @internal: | ||
* https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L4-L5 | ||
*/ | ||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L411 | ||
// function hasProperty<T>(map: ts.MapLike<T>, key: string): boolean; | ||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L655-L656 | ||
export function createCompilerDiagnostic(message: ts.DiagnosticMessage, ...args: any[]): ts.Diagnostic; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the place this is used in the typedoc code does not look needed. so i would say just do not use it. |
||
export function createCompilerDiagnostic(message: ts.DiagnosticMessage): ts.Diagnostic; | ||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L701 | ||
function compareValues<T>(a: T, b: T): number; // Actually returns a ts.Comparison which is internal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would say copy this one. |
||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L790 | ||
function normalizeSlashes(path: string): string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. literally: export function normalizeSlashes(path: string): string {
return path.replace(/\\/g, "/");
} |
||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L795 | ||
function getRootLength(path: string): number; | ||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L845 | ||
// function normalizePath(path: string): string; | ||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L852-L854 | ||
function getDirectoryPath(path: ts.Path): ts.Path; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not see why not use |
||
function getDirectoryPath(path: string): string; | ||
function getDirectoryPath(path: string): any; | ||
|
||
/** | ||
* These functions are in "utilities" and are marked as @internal: | ||
* https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L3-L4 | ||
*/ | ||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L188 | ||
function getSourceFileOfNode(node: ts.Node): ts.SourceFile; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L333 | ||
function getTextOfNode(node: ts.Node, includeTrivia?: boolean): string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L438 | ||
function declarationNameToString(name: ts.DeclarationName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L598 | ||
function getJsDocComments(node: ts.Node, sourceFileOfNode: ts.SourceFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L1487 | ||
function isBindingPattern(node: ts.Node): node is ts.BindingPattern; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can expose this. please file an issue. |
||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L1696 | ||
function getClassExtendsHeritageClauseElement(node: ts.ClassLikeDeclaration | ts.InterfaceDeclaration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not think this is needed frankly. |
||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L1701 | ||
function getClassImplementsHeritageClauseElements(node: ts.ClassLikeDeclaration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nor this. |
||
|
||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L1706 | ||
function getInterfaceBaseTypeNodes(node: ts.InterfaceDeclaration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nor this. |
||
|
||
|
||
/** | ||
* https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L2789-L2924 | ||
* This is large enum of char codes. | ||
* | ||
* Faking the enum as a var (only certain codes are used by TypeDoc) | ||
*/ | ||
var CharacterCodes: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can expose this. though it is just ASCII codes, so you can define them yourself rely. |
||
[key: string]: number; | ||
doubleQuote: number; | ||
space: number; | ||
minus: number; | ||
at: number; | ||
}; | ||
|
||
/** | ||
* https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L2334 | ||
* Duplicating the interface definition :( | ||
*/ | ||
// interface IntrinsicType extends ts.Type { | ||
// intrinsicName: string; | ||
// } | ||
|
||
const optionDeclarations: CommandLineOption[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure why this is needed. but if you have a good use case we can expose it. |
||
|
||
/** | ||
* Command line options | ||
*/ | ||
interface CommandLineOption { | ||
name: string; | ||
type: string; | ||
shortName: string; | ||
description: DiagnosticsEnumValue; | ||
paramType: DiagnosticsEnumValue; | ||
} | ||
|
||
const Diagnostics: { | ||
[key: string]: DiagnosticsEnumValue; | ||
FILE: DiagnosticsEnumValue; | ||
DIRECTORY: DiagnosticsEnumValue; | ||
}; | ||
|
||
interface DiagnosticsEnumValue { | ||
code: number; | ||
category: ts.DiagnosticCategory; | ||
key: string; | ||
message: string; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,22 @@ import {Type, IntrinsicType} from "../../models/index"; | |
import {Component, ConverterTypeComponent, ITypeTypeConverter} from "../components"; | ||
import {Context} from "../context"; | ||
|
||
// TypeScript has an @internal enum set for the intrinsic types: | ||
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L2297-L2298 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason you defined this here instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code in In this case, the The other option, I suppose, is to export it from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. Unless it is needed in multiple places, defining it here is good with me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok with the |
||
// It is not included in the typescript typings, so the enum is cast as `any` to access the `Intrinsic` set. | ||
const IntrinsicTypeFlags = (ts.TypeFlags as any).Intrinsic; | ||
if (IntrinsicTypeFlags === undefined) { | ||
throw new Error("Internal TypeScript API missing: TypeFlags.Intrinsic"); | ||
} | ||
|
||
@Component({name:'type:intrinsic'}) | ||
export class IntrinsicConverter extends ConverterTypeComponent implements ITypeTypeConverter<ts.IntrinsicType> | ||
export class IntrinsicConverter extends ConverterTypeComponent implements ITypeTypeConverter<ts.Type> | ||
{ | ||
/** | ||
* Test whether this converter can handle the given TypeScript type. | ||
*/ | ||
supportsType(context:Context, type:ts.IntrinsicType):boolean { | ||
return !!(type.flags & ts.TypeFlags.Intrinsic); | ||
supportsType(context:Context, type:ts.Type):boolean { | ||
return !!(type.flags & IntrinsicTypeFlags); | ||
} | ||
|
||
|
||
|
@@ -28,7 +35,8 @@ export class IntrinsicConverter extends ConverterTypeComponent implements ITypeT | |
* @param type The intrinsic type that should be converted. | ||
* @returns The type reflection representing the given intrinsic type. | ||
*/ | ||
convertType(context:Context, type:ts.IntrinsicType):IntrinsicType { | ||
return new IntrinsicType(type.intrinsicName); | ||
convertType(context:Context, type:ts.Type):IntrinsicType { | ||
let intrinsicName = context.program.getTypeChecker().typeToString(type); | ||
return new IntrinsicType(intrinsicName); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has anyone created a PR to update this yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find any updates or PRs for shelljs