Minor fixes

This commit is contained in:
Anders Hejlsberg 2019-08-27 06:51:21 -04:00
parent 7753f7b7e6
commit 5310fd0156
2 changed files with 9 additions and 7 deletions

View file

@ -3876,8 +3876,9 @@ namespace ts {
function visitAndTransformType<T>(type: Type, transform: (type: Type) => T) {
const typeId = "" + type.id;
const isConstructorObject = getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & SymbolFlags.Class;
const id = getObjectFlags(type) & ObjectFlags.Reference ? "N" + getNodeId((<DeferredTypeReference>type).node) :
(isConstructorObject ? "+" : "") + getSymbolId(type.symbol);
const id = getObjectFlags(type) & ObjectFlags.Reference && (<TypeReference>type).node ? "N" + getNodeId((<TypeReference>type).node!) :
type.symbol ? (isConstructorObject ? "+" : "") + getSymbolId(type.symbol) :
undefined;
// Since instantiations of the same anonymous type have the same symbol, tracking symbols instead
// of types allows us to catch circular references to instantiations of the same anonymous type
if (!context.visitedTypes) {
@ -29347,12 +29348,9 @@ namespace ts {
if (!(staticBaseType.symbol && staticBaseType.symbol.flags & SymbolFlags.Class) && !(baseConstructorType.flags & TypeFlags.TypeVariable)) {
// When the static base type is a "class-like" constructor function (but not actually a class), we verify
// that all instantiated base constructor signatures return the same type. We can simply compare the type
// references (as opposed to checking the structure of the types) because elsewhere we have already checked
// that the base type is a class or interface type (and not, for example, an anonymous object type).
// (Javascript constructor functions have this property trivially true since their return type is ignored.)
// that all instantiated base constructor signatures return the same type.
const constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode);
if (forEach(constructors, sig => !isJSConstructor(sig.declaration) && getReturnTypeOfSignature(sig) !== baseType)) {
if (forEach(constructors, sig => !isJSConstructor(sig.declaration) && !isTypeIdenticalTo(getReturnTypeOfSignature(sig), baseType))) {
error(baseTypeNode.expression, Diagnostics.Base_constructors_must_all_have_the_same_return_type);
}
}

View file

@ -4203,14 +4203,18 @@ namespace ts {
export interface TypeReference extends ObjectType {
target: GenericType; // Type reference target
node?: ArrayTypeNode | TupleTypeNode;
/* @internal */
mapper?: TypeMapper;
/* @internal */
resolvedTypeArguments?: ReadonlyArray<Type>; // Resolved ype reference type arguments
/* @internal */
literalType?: TypeReference; // Clone of type with ObjectFlags.ArrayLiteral set
}
export interface DeferredTypeReference extends TypeReference {
/* @internal */
node: ArrayTypeNode | TupleTypeNode;
/* @internal */
mapper?: TypeMapper;
}