Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(<ObjectType>type);
Expand Down Expand Up @@ -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(<ObjectType>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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ namespace ts {
}
}

function visitNode<T>(cbNode: (node: Node) => T, node: Node): T | undefined {
function visitNode<T>(cbNode: (node: Node) => T, node?: Node): T | undefined {
if (node) {
return cbNode(node);
}
}

function visitNodeArray<T>(cbNodes: (nodes: Node[]) => T, nodes: Node[]): T | undefined {
function visitNodeArray<T>(cbNodes: (nodes: Node[]) => T, nodes?: Node[]): T | undefined {
if (nodes) {
return cbNodes(nodes);
}
}

function visitEachNode<T>(cbNode: (node: Node) => T, nodes: Node[]): T | undefined {
function visitEachNode<T>(cbNode: (node: Node) => T, nodes?: Node[]): T | undefined {
if (nodes) {
for (const node of nodes) {
const result = cbNode(node);
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/services/jsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 => {
Expand Down
32 changes: 16 additions & 16 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -332,7 +332,7 @@ namespace ts {
return this.name;
}

getDeclarations(): Declaration[] {
getDeclarations(): Declaration[] | undefined {
return this.declarations;
}

Expand Down Expand Up @@ -383,21 +383,21 @@ namespace ts {
flags: TypeFlags;
objectFlags?: ObjectFlags;
id: number;
symbol: Symbol;
symbol?: Symbol;
constructor(checker: TypeChecker, flags: TypeFlags) {
this.checker = checker;
this.flags = flags;
}
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[] {
Expand All @@ -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(<InterfaceType><Type>this)
: undefined;
Expand All @@ -428,7 +428,7 @@ namespace ts {
class SignatureObject implements Signature {
checker: TypeChecker;
declaration: SignatureDeclaration;
typeParameters: TypeParameter[];
typeParameters?: TypeParameter[];
parameters: Symbol[];
thisParameter: Symbol;
resolvedReturnType: Type;
Expand All @@ -438,20 +438,20 @@ 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;
}
getDeclaration(): SignatureDeclaration {
return this.declaration;
}
getTypeParameters(): TypeParameter[] {
getTypeParameters(): TypeParameter[] | undefined {
return this.typeParameters;
}
getParameters(): Symbol[] {
Expand Down
16 changes: 8 additions & 8 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ namespace ts {
getFirstToken(sourceFile?: SourceFile): Node;
getLastToken(sourceFile?: SourceFile): Node;
// See ts.forEachChild for documentation.
forEachChild<T>(cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
forEachChild<T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray<Node>) => 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[];
Expand Down