Address PR feedback

This commit is contained in:
Jason Freeman 2015-03-16 11:04:11 -07:00
parent a29b6fe8c7
commit 9933f6cd00
10 changed files with 10 additions and 193 deletions

View File

@ -4730,13 +4730,16 @@ module ts {
if (!inferredType) {
let inferences = getInferenceCandidates(context, index);
if (inferences.length) {
// Infer widened union or supertype, or the undefined type for no common supertype
// Infer widened union or supertype, or the unknown type for no common supertype
let unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences);
inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType;
inferenceSucceeded = !!unionOrSuperType;
}
else {
// Infer the empty object type when no inferences were made
// Infer the empty object type when no inferences were made. It is important to remember that
// in this case, inference still succeeds, meaning there is no error for not having inference
// candidates. An inference error only occurs when there are *conflicting* candidates, i.e.
// candidates with no common supertype.
inferredType = emptyObjectType;
inferenceSucceeded = true;
}
@ -4746,10 +4749,10 @@ module ts {
let constraint = getConstraintOfTypeParameter(context.typeParameters[index]);
inferredType = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType;
}
// If inference failed, it is necessary to record the index of the failed type parameter (the one we are on).
// It might be that inference has already failed on a later type parameter on a previous call to inferTypeArguments.
// So if this failure is on preceding type parameter, this type parameter is the new failure index.
else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) {
// If inference failed, it is necessary to record the index of the failed type parameter (the one we are on).
// It might be that inference has already failed on a later type parameter on a previous call to inferTypeArguments.
// So if this failure is on preceding type parameter, this type parameter is the new failure index.
context.failedTypeParameterIndex = index;
}
context.inferredTypes[index] = inferredType;

View File

@ -1482,6 +1482,7 @@ module ts {
(t: Type): Type;
}
// @internal
export interface TypeInferences {
primary: Type[]; // Inferences made directly to a type parameter
secondary: Type[]; // Inferences made to a type parameter in a union type
@ -1489,6 +1490,7 @@ module ts {
// If a type parameter is fixed, no more inferences can be made for the type parameter
}
// @internal
export interface InferenceContext {
typeParameters: TypeParameter[]; // Type parameters for which inferences are made
inferUnionTypes: boolean; // Infer union types for disjoint candidates (otherwise undefinedType)

View File

@ -1172,18 +1172,6 @@ declare module "typescript" {
interface TypeMapper {
(t: Type): Type;
}
interface TypeInferences {
primary: Type[];
secondary: Type[];
isFixed: boolean;
}
interface InferenceContext {
typeParameters: TypeParameter[];
inferUnionTypes: boolean;
inferences: TypeInferences[];
inferredTypes: Type[];
failedTypeParameterIndex?: number;
}
interface DiagnosticMessage {
key: string;
category: DiagnosticCategory;

View File

@ -3756,41 +3756,6 @@ declare module "typescript" {
>t : Type
>Type : Type
>Type : Type
}
interface TypeInferences {
>TypeInferences : TypeInferences
primary: Type[];
>primary : Type[]
>Type : Type
secondary: Type[];
>secondary : Type[]
>Type : Type
isFixed: boolean;
>isFixed : boolean
}
interface InferenceContext {
>InferenceContext : InferenceContext
typeParameters: TypeParameter[];
>typeParameters : TypeParameter[]
>TypeParameter : TypeParameter
inferUnionTypes: boolean;
>inferUnionTypes : boolean
inferences: TypeInferences[];
>inferences : TypeInferences[]
>TypeInferences : TypeInferences
inferredTypes: Type[];
>inferredTypes : Type[]
>Type : Type
failedTypeParameterIndex?: number;
>failedTypeParameterIndex : number
}
interface DiagnosticMessage {
>DiagnosticMessage : DiagnosticMessage

View File

@ -1203,18 +1203,6 @@ declare module "typescript" {
interface TypeMapper {
(t: Type): Type;
}
interface TypeInferences {
primary: Type[];
secondary: Type[];
isFixed: boolean;
}
interface InferenceContext {
typeParameters: TypeParameter[];
inferUnionTypes: boolean;
inferences: TypeInferences[];
inferredTypes: Type[];
failedTypeParameterIndex?: number;
}
interface DiagnosticMessage {
key: string;
category: DiagnosticCategory;

View File

@ -3902,41 +3902,6 @@ declare module "typescript" {
>t : Type
>Type : Type
>Type : Type
}
interface TypeInferences {
>TypeInferences : TypeInferences
primary: Type[];
>primary : Type[]
>Type : Type
secondary: Type[];
>secondary : Type[]
>Type : Type
isFixed: boolean;
>isFixed : boolean
}
interface InferenceContext {
>InferenceContext : InferenceContext
typeParameters: TypeParameter[];
>typeParameters : TypeParameter[]
>TypeParameter : TypeParameter
inferUnionTypes: boolean;
>inferUnionTypes : boolean
inferences: TypeInferences[];
>inferences : TypeInferences[]
>TypeInferences : TypeInferences
inferredTypes: Type[];
>inferredTypes : Type[]
>Type : Type
failedTypeParameterIndex?: number;
>failedTypeParameterIndex : number
}
interface DiagnosticMessage {
>DiagnosticMessage : DiagnosticMessage

View File

@ -1204,18 +1204,6 @@ declare module "typescript" {
interface TypeMapper {
(t: Type): Type;
}
interface TypeInferences {
primary: Type[];
secondary: Type[];
isFixed: boolean;
}
interface InferenceContext {
typeParameters: TypeParameter[];
inferUnionTypes: boolean;
inferences: TypeInferences[];
inferredTypes: Type[];
failedTypeParameterIndex?: number;
}
interface DiagnosticMessage {
key: string;
category: DiagnosticCategory;

View File

@ -3852,41 +3852,6 @@ declare module "typescript" {
>t : Type
>Type : Type
>Type : Type
}
interface TypeInferences {
>TypeInferences : TypeInferences
primary: Type[];
>primary : Type[]
>Type : Type
secondary: Type[];
>secondary : Type[]
>Type : Type
isFixed: boolean;
>isFixed : boolean
}
interface InferenceContext {
>InferenceContext : InferenceContext
typeParameters: TypeParameter[];
>typeParameters : TypeParameter[]
>TypeParameter : TypeParameter
inferUnionTypes: boolean;
>inferUnionTypes : boolean
inferences: TypeInferences[];
>inferences : TypeInferences[]
>TypeInferences : TypeInferences
inferredTypes: Type[];
>inferredTypes : Type[]
>Type : Type
failedTypeParameterIndex?: number;
>failedTypeParameterIndex : number
}
interface DiagnosticMessage {
>DiagnosticMessage : DiagnosticMessage

View File

@ -1241,18 +1241,6 @@ declare module "typescript" {
interface TypeMapper {
(t: Type): Type;
}
interface TypeInferences {
primary: Type[];
secondary: Type[];
isFixed: boolean;
}
interface InferenceContext {
typeParameters: TypeParameter[];
inferUnionTypes: boolean;
inferences: TypeInferences[];
inferredTypes: Type[];
failedTypeParameterIndex?: number;
}
interface DiagnosticMessage {
key: string;
category: DiagnosticCategory;

View File

@ -4025,41 +4025,6 @@ declare module "typescript" {
>t : Type
>Type : Type
>Type : Type
}
interface TypeInferences {
>TypeInferences : TypeInferences
primary: Type[];
>primary : Type[]
>Type : Type
secondary: Type[];
>secondary : Type[]
>Type : Type
isFixed: boolean;
>isFixed : boolean
}
interface InferenceContext {
>InferenceContext : InferenceContext
typeParameters: TypeParameter[];
>typeParameters : TypeParameter[]
>TypeParameter : TypeParameter
inferUnionTypes: boolean;
>inferUnionTypes : boolean
inferences: TypeInferences[];
>inferences : TypeInferences[]
>TypeInferences : TypeInferences
inferredTypes: Type[];
>inferredTypes : Type[]
>Type : Type
failedTypeParameterIndex?: number;
>failedTypeParameterIndex : number
}
interface DiagnosticMessage {
>DiagnosticMessage : DiagnosticMessage