Skip to content

Commit b405045

Browse files
committed
Code Review feedback: Quick info will show type of undefined as undefined instead of any
1 parent e1b7652 commit b405045

4 files changed

Lines changed: 8 additions & 13 deletions

File tree

src/compiler/checker.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,11 +1068,7 @@ module ts {
10681068

10691069
function writeType(type: Type, flags: TypeFormatFlags) {
10701070
// Write undefined/null type as any
1071-
if ((flags & TypeFormatFlags.WriteUndefinedAndNullAsAny) &&
1072-
((type.flags & TypeFlags.Undefined) || (type.flags & TypeFlags.Null))) {
1073-
writeKeyword(writer, SyntaxKind.AnyKeyword);
1074-
}
1075-
else if (type.flags & TypeFlags.Intrinsic) {
1071+
if (type.flags & TypeFlags.Intrinsic) {
10761072
// Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving
10771073
writer.writeKind(!(flags & TypeFormatFlags.WriteOwnNameForAnyLike) &&
10781074
(type.flags & TypeFlags.Any) ? "any" : (<IntrinsicType>type).intrinsicName, SymbolDisplayPartKind.keyword);

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ module ts {
686686
WriteArrowStyleSignature = 0x00000008, // Write arrow style signature
687687
WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc)
688688
WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature
689-
WriteUndefinedAndNullAsAny = 0x00000040, // Write undefined and null as any
690689
}
691690

692691
export enum SymbolFormatFlags {

src/services/services.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ module ts {
14121412

14131413
export function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] {
14141414
return mapToDisplayParts(writer => {
1415-
typechecker.writeType(type, writer, enclosingDeclaration, flags | TypeFormatFlags.WriteUndefinedAndNullAsAny);
1415+
typechecker.writeType(type, writer, enclosingDeclaration, flags);
14161416
});
14171417
}
14181418

@@ -1424,7 +1424,7 @@ module ts {
14241424

14251425
function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]{
14261426
return mapToDisplayParts(writer => {
1427-
typechecker.writeSignature(signature, writer, enclosingDeclaration, flags | TypeFormatFlags.WriteUndefinedAndNullAsAny);
1427+
typechecker.writeSignature(signature, writer, enclosingDeclaration, flags);
14281428
});
14291429
}
14301430

@@ -2881,7 +2881,7 @@ module ts {
28812881
// If the type is type parameter, format it specially
28822882
if (type.symbol && type.symbol.flags & SymbolFlags.TypeParameter) {
28832883
var typeParameterParts = mapToDisplayParts(writer => {
2884-
typeResolver.writeTypeParameter(<TypeParameter>type, writer, enclosingDeclaration, TypeFormatFlags.WriteUndefinedAndNullAsAny);
2884+
typeResolver.writeTypeParameter(<TypeParameter>type, writer, enclosingDeclaration);
28852885
});
28862886
displayParts.push.apply(displayParts, typeParameterParts);
28872887
}
@@ -2944,7 +2944,7 @@ module ts {
29442944

29452945
function writeTypeParametersOfSymbol(symbol: Symbol, enclosingDeclaration: Node) {
29462946
var typeParameterParts = mapToDisplayParts(writer => {
2947-
typeResolver.writeTypeParametersOfSymbol(symbol, writer, enclosingDeclaration, TypeFormatFlags.WriteUndefinedAndNullAsAny);
2947+
typeResolver.writeTypeParametersOfSymbol(symbol, writer, enclosingDeclaration);
29482948
});
29492949
displayParts.push.apply(displayParts, typeParameterParts);
29502950
}

tests/cases/fourslash/contextualTyping.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ verify.quickInfoIs("(parameter) s: any");
262262
goTo.marker('33');
263263
verify.quickInfoIs("(var) c3t14: IFoo");
264264
goTo.marker('34');
265-
verify.quickInfoIs("(property) a: any[]");
265+
verify.quickInfoIs("(property) a: undefined[]");
266266
goTo.marker('35');
267267
verify.quickInfoIs("(property) C4T5.foo: (i: number, s: string) => string");
268268
goTo.marker('36');
@@ -334,7 +334,7 @@ verify.quickInfoIs("(parameter) s: any");
334334
goTo.marker('69');
335335
verify.quickInfoIs("(property) t14: IFoo");
336336
goTo.marker('70');
337-
verify.quickInfoIs("(property) a: any[]");
337+
verify.quickInfoIs("(property) a: undefined[]");
338338
goTo.marker('71');
339339
verify.quickInfoIs("(parameter) n: number");
340340
goTo.marker('72');
@@ -394,7 +394,7 @@ verify.quickInfoIs("(parameter) s: any");
394394
goTo.marker('99');
395395
verify.quickInfoIs("(var) c12t14: IFoo");
396396
goTo.marker('100');
397-
verify.quickInfoIs("(property) a: any[]");
397+
verify.quickInfoIs("(property) a: undefined[]");
398398
goTo.marker('101');
399399
verify.quickInfoIs("(function) EF1(a: number, b: number): number");
400400
goTo.marker('102');

0 commit comments

Comments
 (0)