diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8551652c176..6fe27e9dca9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6074,7 +6074,7 @@ namespace ts { * @param type a type to look up property from * @param name a name of property to look up in a given type */ - function getPropertyOfType(type: Type, name: string): Symbol { + function getPropertyOfType(type: Type, name: string): Symbol | undefined { type = getApparentType(type); if (type.flags & TypeFlags.Object) { const resolved = resolveStructuredTypeMembers(type); @@ -6112,14 +6112,14 @@ namespace ts { return getSignaturesOfStructuredType(getApparentType(type), kind); } - function getIndexInfoOfStructuredType(type: Type, kind: IndexKind): IndexInfo { + function getIndexInfoOfStructuredType(type: Type, kind: IndexKind): IndexInfo | undefined { if (type.flags & TypeFlags.StructuredType) { const resolved = resolveStructuredTypeMembers(type); return kind === IndexKind.String ? resolved.stringIndexInfo : resolved.numberIndexInfo; } } - function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type { + function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type | undefined { const info = getIndexInfoOfStructuredType(type, kind); return info && info.type; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 36f08b0b184..87bd36ee3a0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -23,19 +23,19 @@ namespace ts { } } - function visitNode(cbNode: (node: Node) => T, node: Node): T | undefined { + function visitNode(cbNode: (node: Node) => T, node?: Node): T | undefined { if (node) { return cbNode(node); } } - function visitNodeArray(cbNodes: (nodes: Node[]) => T, nodes: Node[]): T | undefined { + function visitNodeArray(cbNodes: (nodes: Node[]) => T, nodes?: Node[]): T | undefined { if (nodes) { return cbNodes(nodes); } } - function visitEachNode(cbNode: (node: Node) => T, nodes: Node[]): T | undefined { + function visitEachNode(cbNode: (node: Node) => T, nodes?: Node[]): T | undefined { if (nodes) { for (const node of nodes) { const result = cbNode(node); @@ -57,7 +57,7 @@ namespace ts { // The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray // callback parameters, but that causes a closure allocation for each invocation with noticeable effects // on performance. - const visitNodes: (cb: ((node: Node) => T) | ((node: Node[]) => T), nodes: Node[]) => T = cbNodeArray ? visitNodeArray : visitEachNode; + const visitNodes: (cb: ((node?: Node) => T | undefined) | ((node?: Node[]) => T | undefined), nodes?: Node[]) => T | undefined = cbNodeArray ? visitNodeArray : visitEachNode; const cbNodes = cbNodeArray || cbNode; switch (node.kind) { case SyntaxKind.QualifiedName: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 98efa1f3e53..a8da09a11c5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2506,10 +2506,10 @@ namespace ts { getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; - getPropertyOfType(type: Type, propertyName: string): Symbol; - getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo; + getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; + getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; - getIndexTypeOfType(type: Type, kind: IndexKind): Type; + getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; getBaseTypeOfLiteralType(type: Type): Type; getWidenedType(type: Type): Type; @@ -3293,7 +3293,7 @@ namespace ts { export interface Signature { declaration: SignatureDeclaration; // Originating declaration - typeParameters?: TypeParameter[]; // Type parameters (undefined if non-generic) + typeParameters?: TypeParameter[]; // Type parameters (undefined if non-generic) parameters: Symbol[]; // Parameters /* @internal */ thisParameter?: Symbol; // symbol of this-type parameter diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index b130a7f754b..8ca55029603 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -44,7 +44,7 @@ namespace ts.JsDoc { let jsDocTagNameCompletionEntries: CompletionEntry[]; let jsDocTagCompletionEntries: CompletionEntry[]; - export function getJsDocCommentsFromDeclarations(declarations: Declaration[]) { + export function getJsDocCommentsFromDeclarations(declarations?: Declaration[]) { // Only collect doc comments from duplicate declarations once: // In case of a union property there might be same declaration multiple times // which only varies in type parameter @@ -69,7 +69,7 @@ namespace ts.JsDoc { return documentationComment; } - export function getJsDocTagsFromDeclarations(declarations: Declaration[]) { + export function getJsDocTagsFromDeclarations(declarations?: Declaration[]) { // Only collect doc comments from duplicate declarations once. const tags: JSDocTagInfo[] = []; forEachUnique(declarations, declaration => { diff --git a/src/services/services.ts b/src/services/services.ts index aca13d7469e..05fe59084b4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -309,15 +309,15 @@ namespace ts { class SymbolObject implements Symbol { flags: SymbolFlags; name: string; - declarations: Declaration[]; + declarations?: Declaration[]; // Undefined is used to indicate the value has not been computed. If, after computing, the - // symbol has no doc comment, then the empty string will be returned. - documentationComment: SymbolDisplayPart[]; + // symbol has no doc comment, then the empty array will be returned. + documentationComment?: SymbolDisplayPart[]; // Undefined is used to indicate the value has not been computed. If, after computing, the // symbol has no JSDoc tags, then the empty array will be returned. - tags: JSDocTagInfo[]; + tags?: JSDocTagInfo[]; constructor(flags: SymbolFlags, name: string) { this.flags = flags; @@ -332,7 +332,7 @@ namespace ts { return this.name; } - getDeclarations(): Declaration[] { + getDeclarations(): Declaration[] | undefined { return this.declarations; } @@ -383,7 +383,7 @@ namespace ts { flags: TypeFlags; objectFlags?: ObjectFlags; id: number; - symbol: Symbol; + symbol?: Symbol; constructor(checker: TypeChecker, flags: TypeFlags) { this.checker = checker; this.flags = flags; @@ -391,13 +391,13 @@ namespace ts { getFlags(): TypeFlags { return this.flags; } - getSymbol(): Symbol { + getSymbol(): Symbol | undefined { return this.symbol; } getProperties(): Symbol[] { return this.checker.getPropertiesOfType(this); } - getProperty(propertyName: string): Symbol { + getProperty(propertyName: string): Symbol | undefined { return this.checker.getPropertyOfType(this, propertyName); } getApparentProperties(): Symbol[] { @@ -409,13 +409,13 @@ namespace ts { getConstructSignatures(): Signature[] { return this.checker.getSignaturesOfType(this, SignatureKind.Construct); } - getStringIndexType(): Type { + getStringIndexType(): Type | undefined { return this.checker.getIndexTypeOfType(this, IndexKind.String); } - getNumberIndexType(): Type { + getNumberIndexType(): Type | undefined { return this.checker.getIndexTypeOfType(this, IndexKind.Number); } - getBaseTypes(): BaseType[] { + getBaseTypes(): BaseType[] | undefined { return this.flags & TypeFlags.Object && this.objectFlags & (ObjectFlags.Class | ObjectFlags.Interface) ? this.checker.getBaseTypes(this) : undefined; @@ -428,7 +428,7 @@ namespace ts { class SignatureObject implements Signature { checker: TypeChecker; declaration: SignatureDeclaration; - typeParameters: TypeParameter[]; + typeParameters?: TypeParameter[]; parameters: Symbol[]; thisParameter: Symbol; resolvedReturnType: Type; @@ -438,12 +438,12 @@ namespace ts { hasLiteralTypes: boolean; // Undefined is used to indicate the value has not been computed. If, after computing, the - // symbol has no doc comment, then the empty string will be returned. - documentationComment: SymbolDisplayPart[]; + // symbol has no doc comment, then the empty array will be returned. + documentationComment?: SymbolDisplayPart[]; // Undefined is used to indicate the value has not been computed. If, after computing, the // symbol has no doc comment, then the empty array will be returned. - jsDocTags: JSDocTagInfo[]; + jsDocTags?: JSDocTagInfo[]; constructor(checker: TypeChecker) { this.checker = checker; @@ -451,7 +451,7 @@ namespace ts { getDeclaration(): SignatureDeclaration { return this.declaration; } - getTypeParameters(): TypeParameter[] { + getTypeParameters(): TypeParameter[] | undefined { return this.typeParameters; } getParameters(): Symbol[] { diff --git a/src/services/types.ts b/src/services/types.ts index 6e6fa245e37..e042276e650 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -19,34 +19,34 @@ namespace ts { getFirstToken(sourceFile?: SourceFile): Node; getLastToken(sourceFile?: SourceFile): Node; // See ts.forEachChild for documentation. - forEachChild(cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T; + forEachChild(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; } export interface Symbol { getFlags(): SymbolFlags; getName(): string; - getDeclarations(): Declaration[]; + getDeclarations(): Declaration[] | undefined; getDocumentationComment(): SymbolDisplayPart[]; getJsDocTags(): JSDocTagInfo[]; } export interface Type { getFlags(): TypeFlags; - getSymbol(): Symbol; + getSymbol(): Symbol | undefined; getProperties(): Symbol[]; - getProperty(propertyName: string): Symbol; + getProperty(propertyName: string): Symbol | undefined; getApparentProperties(): Symbol[]; getCallSignatures(): Signature[]; getConstructSignatures(): Signature[]; - getStringIndexType(): Type; - getNumberIndexType(): Type; - getBaseTypes(): BaseType[]; + getStringIndexType(): Type | undefined; + getNumberIndexType(): Type | undefined; + getBaseTypes(): BaseType[] | undefined; getNonNullableType(): Type; } export interface Signature { getDeclaration(): SignatureDeclaration; - getTypeParameters(): TypeParameter[]; + getTypeParameters(): TypeParameter[] | undefined; getParameters(): Symbol[]; getReturnType(): Type; getDocumentationComment(): SymbolDisplayPart[];