-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeBy DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead
Milestone
Description
interface PromiseHolder {
promise: Promise<any>;
}
class Promise<T> {
constructor(elem: T) { }
}
class Alpha implements PromiseHolder {
promise: Promise<PromiseHolder>;
}
class Beta implements PromiseHolder {
// Must use 'this' in the initializer here
// Cannot have Promise<PromiseHolder> type annotation
promise = new Promise<PromiseHolder>(this);
extra: string;
}
var arr: PromiseHolder[];
var a = new Alpha(), b = new Beta();
arr = [a, b]; // Error in new compiler only: cannot convert {} to PromiseHolder
// Sanity checks
a = b; // OK, Beta is subtype of Alpha
arr[0] = a; // OK, Alpha is subtype of PromiseHolder
arr[0] = b; // OK, Beta is subtype of PromiseHolder
a = arr[0]; // OK, PromiseHolder and Alpha are equivalent under 'any'
Was not an error in TypeScript 1.0; is an error now. Appears specific to the use of this
in the field initializer in Beta
-- this shouldn't change the type inference (due to the explicit generic type parameter), nor should adding a redundant type annotation on the field. Found in internal partner codebase.
Metadata
Metadata
Assignees
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeBy DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead