mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Merge branch 'master' into release-1.5
This commit is contained in:
@@ -5384,38 +5384,43 @@ module ts {
|
||||
if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
|
||||
return type;
|
||||
}
|
||||
// Target type is type of prototype property
|
||||
|
||||
let targetType: Type;
|
||||
let prototypeProperty = getPropertyOfType(rightType, "prototype");
|
||||
if (prototypeProperty) {
|
||||
let targetType = getTypeOfSymbol(prototypeProperty);
|
||||
if (targetType !== anyType) {
|
||||
// Narrow to the target type if it's a subtype of the current type
|
||||
if (isTypeSubtypeOf(targetType, type)) {
|
||||
return targetType;
|
||||
}
|
||||
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
|
||||
if (type.flags & TypeFlags.Union) {
|
||||
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
|
||||
}
|
||||
// Target type is type of the protoype property
|
||||
let prototypePropertyType = getTypeOfSymbol(prototypeProperty);
|
||||
if (prototypePropertyType !== anyType) {
|
||||
targetType = prototypePropertyType;
|
||||
}
|
||||
}
|
||||
// Target type is type of construct signature
|
||||
let constructSignatures: Signature[];
|
||||
if (rightType.flags & TypeFlags.Interface) {
|
||||
constructSignatures = resolveDeclaredMembers(<InterfaceType>rightType).declaredConstructSignatures;
|
||||
}
|
||||
else if (rightType.flags & TypeFlags.Anonymous) {
|
||||
constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct);
|
||||
}
|
||||
|
||||
if (constructSignatures && constructSignatures.length !== 0) {
|
||||
let instanceType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature))));
|
||||
// Pickup type from union types
|
||||
if (type.flags & TypeFlags.Union) {
|
||||
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, instanceType)));
|
||||
if (!targetType) {
|
||||
// Target type is type of construct signature
|
||||
let constructSignatures: Signature[];
|
||||
if (rightType.flags & TypeFlags.Interface) {
|
||||
constructSignatures = resolveDeclaredMembers(<InterfaceType>rightType).declaredConstructSignatures;
|
||||
}
|
||||
else if (rightType.flags & TypeFlags.Anonymous) {
|
||||
constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct);
|
||||
}
|
||||
|
||||
if (constructSignatures && constructSignatures.length) {
|
||||
targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature))));
|
||||
}
|
||||
return instanceType;
|
||||
}
|
||||
|
||||
if (targetType) {
|
||||
// Narrow to the target type if it's a subtype of the current type
|
||||
if (isTypeSubtypeOf(targetType, type)) {
|
||||
return targetType;
|
||||
}
|
||||
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
|
||||
if (type.flags & TypeFlags.Union) {
|
||||
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
2
src/lib/es6.d.ts
vendored
2
src/lib/es6.d.ts
vendored
@@ -3580,6 +3580,7 @@ interface PromiseLike<T> {
|
||||
* @returns A Promise for the completion of which ever callback is executed.
|
||||
*/
|
||||
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
|
||||
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3593,6 +3594,7 @@ interface Promise<T> {
|
||||
* @returns A Promise for the completion of which ever callback is executed.
|
||||
*/
|
||||
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
|
||||
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;
|
||||
|
||||
/**
|
||||
* Attaches a callback for only the rejection of the Promise.
|
||||
|
||||
Reference in New Issue
Block a user