Removing 'T?' type notation (use 'T | null | undefined' instead)

This commit is contained in:
Anders Hejlsberg
2016-03-14 15:11:27 -07:00
parent f774ecf4ec
commit b1bef15a1e
3 changed files with 8 additions and 48 deletions

View File

@@ -2414,7 +2414,6 @@ namespace ts {
case SyntaxKind.UnionType:
case SyntaxKind.IntersectionType:
case SyntaxKind.ParenthesizedType:
case SyntaxKind.NullableType:
return isDeclarationVisible(<Declaration>node.parent);
// Default binding, import specifier and namespace import is visible
@@ -4779,14 +4778,6 @@ namespace ts {
return links.resolvedType;
}
function getTypeFromNullableTypeNode(node: NullableTypeNode): Type {
const links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = getNullableType(getTypeFromTypeNode(node.type));
}
return links.resolvedType;
}
interface TypeSet extends Array<Type> {
containsAny?: boolean;
containsUndefined?: boolean;
@@ -5029,8 +5020,6 @@ namespace ts {
return getTypeFromUnionTypeNode(<UnionTypeNode>node);
case SyntaxKind.IntersectionType:
return getTypeFromIntersectionTypeNode(<IntersectionTypeNode>node);
case SyntaxKind.NullableType:
return getTypeFromNullableTypeNode(<NullableTypeNode>node);
case SyntaxKind.ParenthesizedType:
case SyntaxKind.JSDocNullableType:
case SyntaxKind.JSDocNonNullableType:
@@ -6546,16 +6535,6 @@ namespace ts {
return getNullableKind(type) === TypeFlags.Nullable;
}
function getNullableType(type: Type): Type {
if (!strictNullChecks) {
return type;
}
if (!type.nullableType) {
type.nullableType = isNullableType(type) ? type : getUnionType([type, undefinedType, nullType]);
}
return type.nullableType;
}
function addNullableKind(type: Type, kind: TypeFlags): Type {
if ((getNullableKind(type) & kind) !== kind) {
const types = [type];
@@ -15792,8 +15771,7 @@ namespace ts {
case SyntaxKind.IntersectionType:
return checkUnionOrIntersectionType(<UnionOrIntersectionTypeNode>node);
case SyntaxKind.ParenthesizedType:
case SyntaxKind.NullableType:
return checkSourceElement((<ParenthesizedTypeNode | NullableTypeNode>node).type);
return checkSourceElement((<ParenthesizedTypeNode>node).type);
case SyntaxKind.FunctionDeclaration:
return checkFunctionDeclaration(<FunctionDeclaration>node);
case SyntaxKind.Block:

View File

@@ -127,8 +127,7 @@ namespace ts {
case SyntaxKind.IntersectionType:
return visitNodes(cbNodes, (<UnionOrIntersectionTypeNode>node).types);
case SyntaxKind.ParenthesizedType:
case SyntaxKind.NullableType:
return visitNode(cbNode, (<ParenthesizedTypeNode | NullableTypeNode>node).type);
return visitNode(cbNode, (<ParenthesizedTypeNode>node).type);
case SyntaxKind.ObjectBindingPattern:
case SyntaxKind.ArrayBindingPattern:
return visitNodes(cbNodes, (<BindingPattern>node).elements);
@@ -2426,21 +2425,11 @@ namespace ts {
function parseArrayTypeOrHigher(): TypeNode {
let type = parseNonArrayType();
while (!scanner.hasPrecedingLineBreak()) {
if (parseOptional(SyntaxKind.OpenBracketToken)) {
parseExpected(SyntaxKind.CloseBracketToken);
const node = <ArrayTypeNode>createNode(SyntaxKind.ArrayType, type.pos);
node.elementType = type;
type = finishNode(node);
}
else if (parseOptional(SyntaxKind.QuestionToken)) {
const node = <NullableTypeNode>createNode(SyntaxKind.NullableType, type.pos);
node.type = type;
type = finishNode(node);
}
else {
break;
}
while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
parseExpected(SyntaxKind.CloseBracketToken);
const node = <ArrayTypeNode>createNode(SyntaxKind.ArrayType, type.pos);
node.elementType = type;
type = finishNode(node);
}
return type;
}

View File

@@ -210,7 +210,6 @@ namespace ts {
ParenthesizedType,
ThisType,
StringLiteralType,
NullableType,
// Binding patterns
ObjectBindingPattern,
ArrayBindingPattern,
@@ -357,7 +356,7 @@ namespace ts {
FirstFutureReservedWord = ImplementsKeyword,
LastFutureReservedWord = YieldKeyword,
FirstTypeNode = TypePredicate,
LastTypeNode = NullableType,
LastTypeNode = StringLiteralType,
FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken,
FirstToken = Unknown,
@@ -785,11 +784,6 @@ namespace ts {
_stringLiteralTypeBrand: any;
}
// @kind(SyntaxKind.NullableType)
export interface NullableTypeNode extends TypeNode {
type: TypeNode;
}
// @kind(SyntaxKind.StringLiteral)
export interface StringLiteral extends LiteralExpression {
_stringLiteralBrand: any;
@@ -2152,7 +2146,6 @@ namespace ts {
/* @internal */ id: number; // Unique ID
symbol?: Symbol; // Symbol associated with type (if any)
pattern?: DestructuringPattern; // Destructuring pattern represented by type (if any)
nullableType?: Type; // Cached nullable form of this type
}
/* @internal */