Update more return types to include undefined (#15903)

* Update more return types

* Update types of forEachChild callbacks

* fix line endings
This commit is contained in:
Klaus Meinhardt 2017-05-23 18:54:02 +02:00 committed by Mohamed Hegazy
parent 73ee2feb51
commit f8aae89157
6 changed files with 37 additions and 37 deletions

View File

@ -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);
@ -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;
}

View File

@ -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);
@ -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:

View File

@ -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

View File

@ -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 => {

View File

@ -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(<InterfaceType><Type>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[] {

View File

@ -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[];