Skip to content

Commit b1bef15

Browse files
committed
Removing 'T?' type notation (use 'T | null | undefined' instead)
1 parent f774ecf commit b1bef15

3 files changed

Lines changed: 8 additions & 48 deletions

File tree

‎src/compiler/checker.ts‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,6 @@ namespace ts {
24142414
case SyntaxKind.UnionType:
24152415
case SyntaxKind.IntersectionType:
24162416
case SyntaxKind.ParenthesizedType:
2417-
case SyntaxKind.NullableType:
24182417
return isDeclarationVisible(<Declaration>node.parent);
24192418

24202419
// Default binding, import specifier and namespace import is visible
@@ -4779,14 +4778,6 @@ namespace ts {
47794778
return links.resolvedType;
47804779
}
47814780

4782-
function getTypeFromNullableTypeNode(node: NullableTypeNode): Type {
4783-
const links = getNodeLinks(node);
4784-
if (!links.resolvedType) {
4785-
links.resolvedType = getNullableType(getTypeFromTypeNode(node.type));
4786-
}
4787-
return links.resolvedType;
4788-
}
4789-
47904781
interface TypeSet extends Array<Type> {
47914782
containsAny?: boolean;
47924783
containsUndefined?: boolean;
@@ -5029,8 +5020,6 @@ namespace ts {
50295020
return getTypeFromUnionTypeNode(<UnionTypeNode>node);
50305021
case SyntaxKind.IntersectionType:
50315022
return getTypeFromIntersectionTypeNode(<IntersectionTypeNode>node);
5032-
case SyntaxKind.NullableType:
5033-
return getTypeFromNullableTypeNode(<NullableTypeNode>node);
50345023
case SyntaxKind.ParenthesizedType:
50355024
case SyntaxKind.JSDocNullableType:
50365025
case SyntaxKind.JSDocNonNullableType:
@@ -6546,16 +6535,6 @@ namespace ts {
65466535
return getNullableKind(type) === TypeFlags.Nullable;
65476536
}
65486537

6549-
function getNullableType(type: Type): Type {
6550-
if (!strictNullChecks) {
6551-
return type;
6552-
}
6553-
if (!type.nullableType) {
6554-
type.nullableType = isNullableType(type) ? type : getUnionType([type, undefinedType, nullType]);
6555-
}
6556-
return type.nullableType;
6557-
}
6558-
65596538
function addNullableKind(type: Type, kind: TypeFlags): Type {
65606539
if ((getNullableKind(type) & kind) !== kind) {
65616540
const types = [type];
@@ -15792,8 +15771,7 @@ namespace ts {
1579215771
case SyntaxKind.IntersectionType:
1579315772
return checkUnionOrIntersectionType(<UnionOrIntersectionTypeNode>node);
1579415773
case SyntaxKind.ParenthesizedType:
15795-
case SyntaxKind.NullableType:
15796-
return checkSourceElement((<ParenthesizedTypeNode | NullableTypeNode>node).type);
15774+
return checkSourceElement((<ParenthesizedTypeNode>node).type);
1579715775
case SyntaxKind.FunctionDeclaration:
1579815776
return checkFunctionDeclaration(<FunctionDeclaration>node);
1579915777
case SyntaxKind.Block:

‎src/compiler/parser.ts‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ namespace ts {
127127
case SyntaxKind.IntersectionType:
128128
return visitNodes(cbNodes, (<UnionOrIntersectionTypeNode>node).types);
129129
case SyntaxKind.ParenthesizedType:
130-
case SyntaxKind.NullableType:
131-
return visitNode(cbNode, (<ParenthesizedTypeNode | NullableTypeNode>node).type);
130+
return visitNode(cbNode, (<ParenthesizedTypeNode>node).type);
132131
case SyntaxKind.ObjectBindingPattern:
133132
case SyntaxKind.ArrayBindingPattern:
134133
return visitNodes(cbNodes, (<BindingPattern>node).elements);
@@ -2426,21 +2425,11 @@ namespace ts {
24262425

24272426
function parseArrayTypeOrHigher(): TypeNode {
24282427
let type = parseNonArrayType();
2429-
while (!scanner.hasPrecedingLineBreak()) {
2430-
if (parseOptional(SyntaxKind.OpenBracketToken)) {
2431-
parseExpected(SyntaxKind.CloseBracketToken);
2432-
const node = <ArrayTypeNode>createNode(SyntaxKind.ArrayType, type.pos);
2433-
node.elementType = type;
2434-
type = finishNode(node);
2435-
}
2436-
else if (parseOptional(SyntaxKind.QuestionToken)) {
2437-
const node = <NullableTypeNode>createNode(SyntaxKind.NullableType, type.pos);
2438-
node.type = type;
2439-
type = finishNode(node);
2440-
}
2441-
else {
2442-
break;
2443-
}
2428+
while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
2429+
parseExpected(SyntaxKind.CloseBracketToken);
2430+
const node = <ArrayTypeNode>createNode(SyntaxKind.ArrayType, type.pos);
2431+
node.elementType = type;
2432+
type = finishNode(node);
24442433
}
24452434
return type;
24462435
}

‎src/compiler/types.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ namespace ts {
210210
ParenthesizedType,
211211
ThisType,
212212
StringLiteralType,
213-
NullableType,
214213
// Binding patterns
215214
ObjectBindingPattern,
216215
ArrayBindingPattern,
@@ -357,7 +356,7 @@ namespace ts {
357356
FirstFutureReservedWord = ImplementsKeyword,
358357
LastFutureReservedWord = YieldKeyword,
359358
FirstTypeNode = TypePredicate,
360-
LastTypeNode = NullableType,
359+
LastTypeNode = StringLiteralType,
361360
FirstPunctuation = OpenBraceToken,
362361
LastPunctuation = CaretEqualsToken,
363362
FirstToken = Unknown,
@@ -785,11 +784,6 @@ namespace ts {
785784
_stringLiteralTypeBrand: any;
786785
}
787786

788-
// @kind(SyntaxKind.NullableType)
789-
export interface NullableTypeNode extends TypeNode {
790-
type: TypeNode;
791-
}
792-
793787
// @kind(SyntaxKind.StringLiteral)
794788
export interface StringLiteral extends LiteralExpression {
795789
_stringLiteralBrand: any;
@@ -2152,7 +2146,6 @@ namespace ts {
21522146
/* @internal */ id: number; // Unique ID
21532147
symbol?: Symbol; // Symbol associated with type (if any)
21542148
pattern?: DestructuringPattern; // Destructuring pattern represented by type (if any)
2155-
nullableType?: Type; // Cached nullable form of this type
21562149
}
21572150

21582151
/* @internal */

0 commit comments

Comments
 (0)