Skip to content

Commit f8aae89

Browse files
ajafffmhegazy
authored andcommitted
Update more return types to include undefined (#15903)
* Update more return types * Update types of forEachChild callbacks * fix line endings
1 parent 73ee2fe commit f8aae89

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6074,7 +6074,7 @@ namespace ts {
60746074
* @param type a type to look up property from
60756075
* @param name a name of property to look up in a given type
60766076
*/
6077-
function getPropertyOfType(type: Type, name: string): Symbol {
6077+
function getPropertyOfType(type: Type, name: string): Symbol | undefined {
60786078
type = getApparentType(type);
60796079
if (type.flags & TypeFlags.Object) {
60806080
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
@@ -6112,14 +6112,14 @@ namespace ts {
61126112
return getSignaturesOfStructuredType(getApparentType(type), kind);
61136113
}
61146114

6115-
function getIndexInfoOfStructuredType(type: Type, kind: IndexKind): IndexInfo {
6115+
function getIndexInfoOfStructuredType(type: Type, kind: IndexKind): IndexInfo | undefined {
61166116
if (type.flags & TypeFlags.StructuredType) {
61176117
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
61186118
return kind === IndexKind.String ? resolved.stringIndexInfo : resolved.numberIndexInfo;
61196119
}
61206120
}
61216121

6122-
function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type {
6122+
function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type | undefined {
61236123
const info = getIndexInfoOfStructuredType(type, kind);
61246124
return info && info.type;
61256125
}

src/compiler/parser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ namespace ts {
2323
}
2424
}
2525

26-
function visitNode<T>(cbNode: (node: Node) => T, node: Node): T | undefined {
26+
function visitNode<T>(cbNode: (node: Node) => T, node?: Node): T | undefined {
2727
if (node) {
2828
return cbNode(node);
2929
}
3030
}
3131

32-
function visitNodeArray<T>(cbNodes: (nodes: Node[]) => T, nodes: Node[]): T | undefined {
32+
function visitNodeArray<T>(cbNodes: (nodes: Node[]) => T, nodes?: Node[]): T | undefined {
3333
if (nodes) {
3434
return cbNodes(nodes);
3535
}
3636
}
3737

38-
function visitEachNode<T>(cbNode: (node: Node) => T, nodes: Node[]): T | undefined {
38+
function visitEachNode<T>(cbNode: (node: Node) => T, nodes?: Node[]): T | undefined {
3939
if (nodes) {
4040
for (const node of nodes) {
4141
const result = cbNode(node);
@@ -57,7 +57,7 @@ namespace ts {
5757
// The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray
5858
// callback parameters, but that causes a closure allocation for each invocation with noticeable effects
5959
// on performance.
60-
const visitNodes: (cb: ((node: Node) => T) | ((node: Node[]) => T), nodes: Node[]) => T = cbNodeArray ? visitNodeArray : visitEachNode;
60+
const visitNodes: (cb: ((node?: Node) => T | undefined) | ((node?: Node[]) => T | undefined), nodes?: Node[]) => T | undefined = cbNodeArray ? visitNodeArray : visitEachNode;
6161
const cbNodes = cbNodeArray || cbNode;
6262
switch (node.kind) {
6363
case SyntaxKind.QualifiedName:

src/compiler/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,10 +2506,10 @@ namespace ts {
25062506
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
25072507
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
25082508
getPropertiesOfType(type: Type): Symbol[];
2509-
getPropertyOfType(type: Type, propertyName: string): Symbol;
2510-
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo;
2509+
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
2510+
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined;
25112511
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
2512-
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
2512+
getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined;
25132513
getBaseTypes(type: InterfaceType): BaseType[];
25142514
getBaseTypeOfLiteralType(type: Type): Type;
25152515
getWidenedType(type: Type): Type;
@@ -3293,7 +3293,7 @@ namespace ts {
32933293

32943294
export interface Signature {
32953295
declaration: SignatureDeclaration; // Originating declaration
3296-
typeParameters?: TypeParameter[]; // Type parameters (undefined if non-generic)
3296+
typeParameters?: TypeParameter[]; // Type parameters (undefined if non-generic)
32973297
parameters: Symbol[]; // Parameters
32983298
/* @internal */
32993299
thisParameter?: Symbol; // symbol of this-type parameter

src/services/jsDoc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace ts.JsDoc {
4444
let jsDocTagNameCompletionEntries: CompletionEntry[];
4545
let jsDocTagCompletionEntries: CompletionEntry[];
4646

47-
export function getJsDocCommentsFromDeclarations(declarations: Declaration[]) {
47+
export function getJsDocCommentsFromDeclarations(declarations?: Declaration[]) {
4848
// Only collect doc comments from duplicate declarations once:
4949
// In case of a union property there might be same declaration multiple times
5050
// which only varies in type parameter
@@ -69,7 +69,7 @@ namespace ts.JsDoc {
6969
return documentationComment;
7070
}
7171

72-
export function getJsDocTagsFromDeclarations(declarations: Declaration[]) {
72+
export function getJsDocTagsFromDeclarations(declarations?: Declaration[]) {
7373
// Only collect doc comments from duplicate declarations once.
7474
const tags: JSDocTagInfo[] = [];
7575
forEachUnique(declarations, declaration => {

src/services/services.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,15 @@ namespace ts {
309309
class SymbolObject implements Symbol {
310310
flags: SymbolFlags;
311311
name: string;
312-
declarations: Declaration[];
312+
declarations?: Declaration[];
313313

314314
// Undefined is used to indicate the value has not been computed. If, after computing, the
315-
// symbol has no doc comment, then the empty string will be returned.
316-
documentationComment: SymbolDisplayPart[];
315+
// symbol has no doc comment, then the empty array will be returned.
316+
documentationComment?: SymbolDisplayPart[];
317317

318318
// Undefined is used to indicate the value has not been computed. If, after computing, the
319319
// symbol has no JSDoc tags, then the empty array will be returned.
320-
tags: JSDocTagInfo[];
320+
tags?: JSDocTagInfo[];
321321

322322
constructor(flags: SymbolFlags, name: string) {
323323
this.flags = flags;
@@ -332,7 +332,7 @@ namespace ts {
332332
return this.name;
333333
}
334334

335-
getDeclarations(): Declaration[] {
335+
getDeclarations(): Declaration[] | undefined {
336336
return this.declarations;
337337
}
338338

@@ -383,21 +383,21 @@ namespace ts {
383383
flags: TypeFlags;
384384
objectFlags?: ObjectFlags;
385385
id: number;
386-
symbol: Symbol;
386+
symbol?: Symbol;
387387
constructor(checker: TypeChecker, flags: TypeFlags) {
388388
this.checker = checker;
389389
this.flags = flags;
390390
}
391391
getFlags(): TypeFlags {
392392
return this.flags;
393393
}
394-
getSymbol(): Symbol {
394+
getSymbol(): Symbol | undefined {
395395
return this.symbol;
396396
}
397397
getProperties(): Symbol[] {
398398
return this.checker.getPropertiesOfType(this);
399399
}
400-
getProperty(propertyName: string): Symbol {
400+
getProperty(propertyName: string): Symbol | undefined {
401401
return this.checker.getPropertyOfType(this, propertyName);
402402
}
403403
getApparentProperties(): Symbol[] {
@@ -409,13 +409,13 @@ namespace ts {
409409
getConstructSignatures(): Signature[] {
410410
return this.checker.getSignaturesOfType(this, SignatureKind.Construct);
411411
}
412-
getStringIndexType(): Type {
412+
getStringIndexType(): Type | undefined {
413413
return this.checker.getIndexTypeOfType(this, IndexKind.String);
414414
}
415-
getNumberIndexType(): Type {
415+
getNumberIndexType(): Type | undefined {
416416
return this.checker.getIndexTypeOfType(this, IndexKind.Number);
417417
}
418-
getBaseTypes(): BaseType[] {
418+
getBaseTypes(): BaseType[] | undefined {
419419
return this.flags & TypeFlags.Object && this.objectFlags & (ObjectFlags.Class | ObjectFlags.Interface)
420420
? this.checker.getBaseTypes(<InterfaceType><Type>this)
421421
: undefined;
@@ -428,7 +428,7 @@ namespace ts {
428428
class SignatureObject implements Signature {
429429
checker: TypeChecker;
430430
declaration: SignatureDeclaration;
431-
typeParameters: TypeParameter[];
431+
typeParameters?: TypeParameter[];
432432
parameters: Symbol[];
433433
thisParameter: Symbol;
434434
resolvedReturnType: Type;
@@ -438,20 +438,20 @@ namespace ts {
438438
hasLiteralTypes: boolean;
439439

440440
// Undefined is used to indicate the value has not been computed. If, after computing, the
441-
// symbol has no doc comment, then the empty string will be returned.
442-
documentationComment: SymbolDisplayPart[];
441+
// symbol has no doc comment, then the empty array will be returned.
442+
documentationComment?: SymbolDisplayPart[];
443443

444444
// Undefined is used to indicate the value has not been computed. If, after computing, the
445445
// symbol has no doc comment, then the empty array will be returned.
446-
jsDocTags: JSDocTagInfo[];
446+
jsDocTags?: JSDocTagInfo[];
447447

448448
constructor(checker: TypeChecker) {
449449
this.checker = checker;
450450
}
451451
getDeclaration(): SignatureDeclaration {
452452
return this.declaration;
453453
}
454-
getTypeParameters(): TypeParameter[] {
454+
getTypeParameters(): TypeParameter[] | undefined {
455455
return this.typeParameters;
456456
}
457457
getParameters(): Symbol[] {

src/services/types.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ namespace ts {
1919
getFirstToken(sourceFile?: SourceFile): Node;
2020
getLastToken(sourceFile?: SourceFile): Node;
2121
// See ts.forEachChild for documentation.
22-
forEachChild<T>(cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
22+
forEachChild<T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray<Node>) => T | undefined): T | undefined;
2323
}
2424

2525
export interface Symbol {
2626
getFlags(): SymbolFlags;
2727
getName(): string;
28-
getDeclarations(): Declaration[];
28+
getDeclarations(): Declaration[] | undefined;
2929
getDocumentationComment(): SymbolDisplayPart[];
3030
getJsDocTags(): JSDocTagInfo[];
3131
}
3232

3333
export interface Type {
3434
getFlags(): TypeFlags;
35-
getSymbol(): Symbol;
35+
getSymbol(): Symbol | undefined;
3636
getProperties(): Symbol[];
37-
getProperty(propertyName: string): Symbol;
37+
getProperty(propertyName: string): Symbol | undefined;
3838
getApparentProperties(): Symbol[];
3939
getCallSignatures(): Signature[];
4040
getConstructSignatures(): Signature[];
41-
getStringIndexType(): Type;
42-
getNumberIndexType(): Type;
43-
getBaseTypes(): BaseType[];
41+
getStringIndexType(): Type | undefined;
42+
getNumberIndexType(): Type | undefined;
43+
getBaseTypes(): BaseType[] | undefined;
4444
getNonNullableType(): Type;
4545
}
4646

4747
export interface Signature {
4848
getDeclaration(): SignatureDeclaration;
49-
getTypeParameters(): TypeParameter[];
49+
getTypeParameters(): TypeParameter[] | undefined;
5050
getParameters(): Symbol[];
5151
getReturnType(): Type;
5252
getDocumentationComment(): SymbolDisplayPart[];

0 commit comments

Comments
 (0)