Merge pull request #22956 from Microsoft/PortFixesToRelease2.8

Port fixes to release2.8
This commit is contained in:
Mohamed Hegazy
2018-03-28 12:41:31 -07:00
committed by GitHub
15 changed files with 827 additions and 12 deletions

View File

@@ -4083,8 +4083,7 @@ namespace ts {
if (strictNullChecks && declaration.flags & NodeFlags.Ambient && isParameterDeclaration(declaration)) {
parentType = getNonNullableType(parentType);
}
const propType = getTypeOfPropertyOfType(parentType, text);
const declaredType = propType && getConstraintForLocation(propType, declaration.name);
const declaredType = getConstraintForLocation(getTypeOfPropertyOfType(parentType, text), declaration.name);
type = declaredType && getFlowTypeOfReference(declaration, declaredType) ||
isNumericLiteralName(text) && getIndexTypeOfType(parentType, IndexKind.Number) ||
getIndexTypeOfType(parentType, IndexKind.String);
@@ -10227,8 +10226,11 @@ namespace ts {
}
else if (source.flags & TypeFlags.Conditional) {
if (target.flags & TypeFlags.Conditional) {
if (isTypeIdenticalTo((<ConditionalType>source).checkType, (<ConditionalType>target).checkType) &&
isTypeIdenticalTo((<ConditionalType>source).extendsType, (<ConditionalType>target).extendsType)) {
// Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
// one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
// and Y1 is related to Y2.
if (isTypeIdenticalTo((<ConditionalType>source).extendsType, (<ConditionalType>target).extendsType) &&
(isRelatedTo((<ConditionalType>source).checkType, (<ConditionalType>target).checkType) || isRelatedTo((<ConditionalType>target).checkType, (<ConditionalType>source).checkType))) {
if (result = isRelatedTo(getTrueTypeFromConditionalType(<ConditionalType>source), getTrueTypeFromConditionalType(<ConditionalType>target), reportErrors)) {
result &= isRelatedTo(getFalseTypeFromConditionalType(<ConditionalType>source), getFalseTypeFromConditionalType(<ConditionalType>target), reportErrors);
}
@@ -12408,7 +12410,7 @@ namespace ts {
function getTypeOfDestructuredProperty(type: Type, name: PropertyName) {
const text = getTextOfPropertyName(name);
return getTypeOfPropertyOfType(type, text) ||
return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) ||
isNumericLiteralName(text) && getIndexTypeOfType(type, IndexKind.Number) ||
getIndexTypeOfType(type, IndexKind.String) ||
unknownType;
@@ -13524,7 +13526,7 @@ namespace ts {
// and the type of the node includes type variables with constraints that are nullable, we fetch the
// apparent type of the node *before* performing control flow analysis such that narrowings apply to
// the constraint type.
if (isConstraintPosition(node) && forEachType(type, typeHasNullableConstraint)) {
if (type && isConstraintPosition(node) && forEachType(type, typeHasNullableConstraint)) {
return mapType(getWidenedType(type), getBaseConstraintOrType);
}
return type;

View File

@@ -36,6 +36,10 @@ namespace ts.codefix {
function getNodes(sourceFile: SourceFile, start: number): { insertBefore: Node, returnType: TypeNode | undefined } | undefined {
const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
const containingFunction = getContainingFunction(token);
if (!containingFunction) {
return;
}
let insertBefore: Node | undefined;
switch (containingFunction.kind) {
case SyntaxKind.MethodDeclaration:

View File

@@ -64,17 +64,21 @@ namespace ts.codefix {
return undefined;
}
const { parent } = token;
switch (errorCode) {
// Variable and Property declarations
case Diagnostics.Member_0_implicitly_has_an_1_type.code:
case Diagnostics.Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined.code:
annotateVariableDeclaration(changes, sourceFile, <PropertyDeclaration | PropertySignature | VariableDeclaration>token.parent, program, cancellationToken);
return token.parent as Declaration;
if (isVariableDeclaration(parent) || isPropertyDeclaration(parent) || isPropertySignature(parent)) { // handle bad location
annotateVariableDeclaration(changes, sourceFile, parent, program, cancellationToken);
return parent;
}
return undefined;
case Diagnostics.Variable_0_implicitly_has_an_1_type.code: {
const symbol = program.getTypeChecker().getSymbolAtLocation(token);
if (symbol && symbol.valueDeclaration) {
annotateVariableDeclaration(changes, sourceFile, <VariableDeclaration>symbol.valueDeclaration, program, cancellationToken);
if (symbol && symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration)) {
annotateVariableDeclaration(changes, sourceFile, symbol.valueDeclaration, program, cancellationToken);
return symbol.valueDeclaration;
}
}
@@ -95,7 +99,7 @@ namespace ts.codefix {
// falls through
case Diagnostics.Rest_parameter_0_implicitly_has_an_any_type.code:
if (!seenFunctions || addToSeen(seenFunctions, getNodeId(containingFunction))) {
const param = cast(token.parent, isParameter);
const param = cast(parent, isParameter);
annotateParameters(changes, param, containingFunction, sourceFile, program, cancellationToken);
return param;
}

View File

@@ -1628,7 +1628,7 @@ namespace ts.Completions {
}
function isFromClassElementDeclaration(node: Node) {
return isClassElement(node.parent) && isClassLike(node.parent.parent);
return node.parent && isClassElement(node.parent) && isClassLike(node.parent.parent);
}
function isParameterOfConstructorDeclaration(node: Node) {

View File

@@ -0,0 +1,90 @@
tests/cases/conformance/types/conditional/conditionalTypes2.ts(15,5): error TS2322: Type 'Covariant<A>' is not assignable to type 'Covariant<B>'.
Type 'A' is not assignable to type 'B'.
tests/cases/conformance/types/conditional/conditionalTypes2.ts(19,5): error TS2322: Type 'Contravariant<B>' is not assignable to type 'Contravariant<A>'.
Type 'A' is not assignable to type 'B'.
tests/cases/conformance/types/conditional/conditionalTypes2.ts(24,5): error TS2322: Type 'Invariant<B>' is not assignable to type 'Invariant<A>'.
Types of property 'foo' are incompatible.
Type 'B extends string ? keyof B : B' is not assignable to type 'A extends string ? keyof A : A'.
Type 'keyof B' is not assignable to type 'keyof A'.
tests/cases/conformance/types/conditional/conditionalTypes2.ts(25,5): error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
Types of property 'foo' are incompatible.
Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'.
Type 'A' is not assignable to type 'B'.
==== tests/cases/conformance/types/conditional/conditionalTypes2.ts (4 errors) ====
interface Covariant<T> {
foo: T extends string ? T : number;
}
interface Contravariant<T> {
foo: T extends string ? keyof T : number;
}
interface Invariant<T> {
foo: T extends string ? keyof T : T;
}
function f1<A, B extends A>(a: Covariant<A>, b: Covariant<B>) {
a = b;
b = a; // Error
~
!!! error TS2322: Type 'Covariant<A>' is not assignable to type 'Covariant<B>'.
!!! error TS2322: Type 'A' is not assignable to type 'B'.
}
function f2<A, B extends A>(a: Contravariant<A>, b: Contravariant<B>) {
a = b; // Error
~
!!! error TS2322: Type 'Contravariant<B>' is not assignable to type 'Contravariant<A>'.
!!! error TS2322: Type 'A' is not assignable to type 'B'.
b = a;
}
function f3<A, B extends A>(a: Invariant<A>, b: Invariant<B>) {
a = b; // Error
~
!!! error TS2322: Type 'Invariant<B>' is not assignable to type 'Invariant<A>'.
!!! error TS2322: Types of property 'foo' are incompatible.
!!! error TS2322: Type 'B extends string ? keyof B : B' is not assignable to type 'A extends string ? keyof A : A'.
!!! error TS2322: Type 'keyof B' is not assignable to type 'keyof A'.
b = a; // Error
~
!!! error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
!!! error TS2322: Types of property 'foo' are incompatible.
!!! error TS2322: Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'.
!!! error TS2322: Type 'A' is not assignable to type 'B'.
}
// Repros from #22860
class Opt<T> {
toVector(): Vector<T> {
return <any>undefined;
}
}
interface Seq<T> {
tail(): Opt<Seq<T>>;
}
class Vector<T> implements Seq<T> {
tail(): Opt<Vector<T>> {
return <any>undefined;
}
partition2<U extends T>(predicate:(v:T)=>v is U): [Vector<U>,Vector<Exclude<T, U>>];
partition2(predicate:(x:T)=>boolean): [Vector<T>,Vector<T>];
partition2<U extends T>(predicate:(v:T)=>boolean): [Vector<U>,Vector<any>] {
return <any>undefined;
}
}
interface A1<T> {
bat: B1<A1<T>>;
}
interface B1<T> extends A1<T> {
bat: B1<B1<T>>;
boom: T extends any ? true : true
}

View File

@@ -0,0 +1,128 @@
//// [conditionalTypes2.ts]
interface Covariant<T> {
foo: T extends string ? T : number;
}
interface Contravariant<T> {
foo: T extends string ? keyof T : number;
}
interface Invariant<T> {
foo: T extends string ? keyof T : T;
}
function f1<A, B extends A>(a: Covariant<A>, b: Covariant<B>) {
a = b;
b = a; // Error
}
function f2<A, B extends A>(a: Contravariant<A>, b: Contravariant<B>) {
a = b; // Error
b = a;
}
function f3<A, B extends A>(a: Invariant<A>, b: Invariant<B>) {
a = b; // Error
b = a; // Error
}
// Repros from #22860
class Opt<T> {
toVector(): Vector<T> {
return <any>undefined;
}
}
interface Seq<T> {
tail(): Opt<Seq<T>>;
}
class Vector<T> implements Seq<T> {
tail(): Opt<Vector<T>> {
return <any>undefined;
}
partition2<U extends T>(predicate:(v:T)=>v is U): [Vector<U>,Vector<Exclude<T, U>>];
partition2(predicate:(x:T)=>boolean): [Vector<T>,Vector<T>];
partition2<U extends T>(predicate:(v:T)=>boolean): [Vector<U>,Vector<any>] {
return <any>undefined;
}
}
interface A1<T> {
bat: B1<A1<T>>;
}
interface B1<T> extends A1<T> {
bat: B1<B1<T>>;
boom: T extends any ? true : true
}
//// [conditionalTypes2.js]
"use strict";
function f1(a, b) {
a = b;
b = a; // Error
}
function f2(a, b) {
a = b; // Error
b = a;
}
function f3(a, b) {
a = b; // Error
b = a; // Error
}
// Repros from #22860
var Opt = /** @class */ (function () {
function Opt() {
}
Opt.prototype.toVector = function () {
return undefined;
};
return Opt;
}());
var Vector = /** @class */ (function () {
function Vector() {
}
Vector.prototype.tail = function () {
return undefined;
};
Vector.prototype.partition2 = function (predicate) {
return undefined;
};
return Vector;
}());
//// [conditionalTypes2.d.ts]
interface Covariant<T> {
foo: T extends string ? T : number;
}
interface Contravariant<T> {
foo: T extends string ? keyof T : number;
}
interface Invariant<T> {
foo: T extends string ? keyof T : T;
}
declare function f1<A, B extends A>(a: Covariant<A>, b: Covariant<B>): void;
declare function f2<A, B extends A>(a: Contravariant<A>, b: Contravariant<B>): void;
declare function f3<A, B extends A>(a: Invariant<A>, b: Invariant<B>): void;
declare class Opt<T> {
toVector(): Vector<T>;
}
interface Seq<T> {
tail(): Opt<Seq<T>>;
}
declare class Vector<T> implements Seq<T> {
tail(): Opt<Vector<T>>;
partition2<U extends T>(predicate: (v: T) => v is U): [Vector<U>, Vector<Exclude<T, U>>];
partition2(predicate: (x: T) => boolean): [Vector<T>, Vector<T>];
}
interface A1<T> {
bat: B1<A1<T>>;
}
interface B1<T> extends A1<T> {
bat: B1<B1<T>>;
boom: T extends any ? true : true;
}

View File

@@ -0,0 +1,207 @@
=== tests/cases/conformance/types/conditional/conditionalTypes2.ts ===
interface Covariant<T> {
>Covariant : Symbol(Covariant, Decl(conditionalTypes2.ts, 0, 0))
>T : Symbol(T, Decl(conditionalTypes2.ts, 0, 20))
foo: T extends string ? T : number;
>foo : Symbol(Covariant.foo, Decl(conditionalTypes2.ts, 0, 24))
>T : Symbol(T, Decl(conditionalTypes2.ts, 0, 20))
>T : Symbol(T, Decl(conditionalTypes2.ts, 0, 20))
}
interface Contravariant<T> {
>Contravariant : Symbol(Contravariant, Decl(conditionalTypes2.ts, 2, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 4, 24))
foo: T extends string ? keyof T : number;
>foo : Symbol(Contravariant.foo, Decl(conditionalTypes2.ts, 4, 28))
>T : Symbol(T, Decl(conditionalTypes2.ts, 4, 24))
>T : Symbol(T, Decl(conditionalTypes2.ts, 4, 24))
}
interface Invariant<T> {
>Invariant : Symbol(Invariant, Decl(conditionalTypes2.ts, 6, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 8, 20))
foo: T extends string ? keyof T : T;
>foo : Symbol(Invariant.foo, Decl(conditionalTypes2.ts, 8, 24))
>T : Symbol(T, Decl(conditionalTypes2.ts, 8, 20))
>T : Symbol(T, Decl(conditionalTypes2.ts, 8, 20))
>T : Symbol(T, Decl(conditionalTypes2.ts, 8, 20))
}
function f1<A, B extends A>(a: Covariant<A>, b: Covariant<B>) {
>f1 : Symbol(f1, Decl(conditionalTypes2.ts, 10, 1))
>A : Symbol(A, Decl(conditionalTypes2.ts, 12, 12))
>B : Symbol(B, Decl(conditionalTypes2.ts, 12, 14))
>A : Symbol(A, Decl(conditionalTypes2.ts, 12, 12))
>a : Symbol(a, Decl(conditionalTypes2.ts, 12, 28))
>Covariant : Symbol(Covariant, Decl(conditionalTypes2.ts, 0, 0))
>A : Symbol(A, Decl(conditionalTypes2.ts, 12, 12))
>b : Symbol(b, Decl(conditionalTypes2.ts, 12, 44))
>Covariant : Symbol(Covariant, Decl(conditionalTypes2.ts, 0, 0))
>B : Symbol(B, Decl(conditionalTypes2.ts, 12, 14))
a = b;
>a : Symbol(a, Decl(conditionalTypes2.ts, 12, 28))
>b : Symbol(b, Decl(conditionalTypes2.ts, 12, 44))
b = a; // Error
>b : Symbol(b, Decl(conditionalTypes2.ts, 12, 44))
>a : Symbol(a, Decl(conditionalTypes2.ts, 12, 28))
}
function f2<A, B extends A>(a: Contravariant<A>, b: Contravariant<B>) {
>f2 : Symbol(f2, Decl(conditionalTypes2.ts, 15, 1))
>A : Symbol(A, Decl(conditionalTypes2.ts, 17, 12))
>B : Symbol(B, Decl(conditionalTypes2.ts, 17, 14))
>A : Symbol(A, Decl(conditionalTypes2.ts, 17, 12))
>a : Symbol(a, Decl(conditionalTypes2.ts, 17, 28))
>Contravariant : Symbol(Contravariant, Decl(conditionalTypes2.ts, 2, 1))
>A : Symbol(A, Decl(conditionalTypes2.ts, 17, 12))
>b : Symbol(b, Decl(conditionalTypes2.ts, 17, 48))
>Contravariant : Symbol(Contravariant, Decl(conditionalTypes2.ts, 2, 1))
>B : Symbol(B, Decl(conditionalTypes2.ts, 17, 14))
a = b; // Error
>a : Symbol(a, Decl(conditionalTypes2.ts, 17, 28))
>b : Symbol(b, Decl(conditionalTypes2.ts, 17, 48))
b = a;
>b : Symbol(b, Decl(conditionalTypes2.ts, 17, 48))
>a : Symbol(a, Decl(conditionalTypes2.ts, 17, 28))
}
function f3<A, B extends A>(a: Invariant<A>, b: Invariant<B>) {
>f3 : Symbol(f3, Decl(conditionalTypes2.ts, 20, 1))
>A : Symbol(A, Decl(conditionalTypes2.ts, 22, 12))
>B : Symbol(B, Decl(conditionalTypes2.ts, 22, 14))
>A : Symbol(A, Decl(conditionalTypes2.ts, 22, 12))
>a : Symbol(a, Decl(conditionalTypes2.ts, 22, 28))
>Invariant : Symbol(Invariant, Decl(conditionalTypes2.ts, 6, 1))
>A : Symbol(A, Decl(conditionalTypes2.ts, 22, 12))
>b : Symbol(b, Decl(conditionalTypes2.ts, 22, 44))
>Invariant : Symbol(Invariant, Decl(conditionalTypes2.ts, 6, 1))
>B : Symbol(B, Decl(conditionalTypes2.ts, 22, 14))
a = b; // Error
>a : Symbol(a, Decl(conditionalTypes2.ts, 22, 28))
>b : Symbol(b, Decl(conditionalTypes2.ts, 22, 44))
b = a; // Error
>b : Symbol(b, Decl(conditionalTypes2.ts, 22, 44))
>a : Symbol(a, Decl(conditionalTypes2.ts, 22, 28))
}
// Repros from #22860
class Opt<T> {
>Opt : Symbol(Opt, Decl(conditionalTypes2.ts, 25, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 29, 10))
toVector(): Vector<T> {
>toVector : Symbol(Opt.toVector, Decl(conditionalTypes2.ts, 29, 14))
>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 37, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 29, 10))
return <any>undefined;
>undefined : Symbol(undefined)
}
}
interface Seq<T> {
>Seq : Symbol(Seq, Decl(conditionalTypes2.ts, 33, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 35, 14))
tail(): Opt<Seq<T>>;
>tail : Symbol(Seq.tail, Decl(conditionalTypes2.ts, 35, 18))
>Opt : Symbol(Opt, Decl(conditionalTypes2.ts, 25, 1))
>Seq : Symbol(Seq, Decl(conditionalTypes2.ts, 33, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 35, 14))
}
class Vector<T> implements Seq<T> {
>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 37, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
>Seq : Symbol(Seq, Decl(conditionalTypes2.ts, 33, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
tail(): Opt<Vector<T>> {
>tail : Symbol(Vector.tail, Decl(conditionalTypes2.ts, 39, 35))
>Opt : Symbol(Opt, Decl(conditionalTypes2.ts, 25, 1))
>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 37, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
return <any>undefined;
>undefined : Symbol(undefined)
}
partition2<U extends T>(predicate:(v:T)=>v is U): [Vector<U>,Vector<Exclude<T, U>>];
>partition2 : Symbol(Vector.partition2, Decl(conditionalTypes2.ts, 42, 5), Decl(conditionalTypes2.ts, 43, 88), Decl(conditionalTypes2.ts, 44, 64))
>U : Symbol(U, Decl(conditionalTypes2.ts, 43, 15))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
>predicate : Symbol(predicate, Decl(conditionalTypes2.ts, 43, 28))
>v : Symbol(v, Decl(conditionalTypes2.ts, 43, 39))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
>v : Symbol(v, Decl(conditionalTypes2.ts, 43, 39))
>U : Symbol(U, Decl(conditionalTypes2.ts, 43, 15))
>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 37, 1))
>U : Symbol(U, Decl(conditionalTypes2.ts, 43, 15))
>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 37, 1))
>Exclude : Symbol(Exclude, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
>U : Symbol(U, Decl(conditionalTypes2.ts, 43, 15))
partition2(predicate:(x:T)=>boolean): [Vector<T>,Vector<T>];
>partition2 : Symbol(Vector.partition2, Decl(conditionalTypes2.ts, 42, 5), Decl(conditionalTypes2.ts, 43, 88), Decl(conditionalTypes2.ts, 44, 64))
>predicate : Symbol(predicate, Decl(conditionalTypes2.ts, 44, 15))
>x : Symbol(x, Decl(conditionalTypes2.ts, 44, 26))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 37, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 37, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
partition2<U extends T>(predicate:(v:T)=>boolean): [Vector<U>,Vector<any>] {
>partition2 : Symbol(Vector.partition2, Decl(conditionalTypes2.ts, 42, 5), Decl(conditionalTypes2.ts, 43, 88), Decl(conditionalTypes2.ts, 44, 64))
>U : Symbol(U, Decl(conditionalTypes2.ts, 45, 15))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
>predicate : Symbol(predicate, Decl(conditionalTypes2.ts, 45, 28))
>v : Symbol(v, Decl(conditionalTypes2.ts, 45, 39))
>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13))
>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 37, 1))
>U : Symbol(U, Decl(conditionalTypes2.ts, 45, 15))
>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 37, 1))
return <any>undefined;
>undefined : Symbol(undefined)
}
}
interface A1<T> {
>A1 : Symbol(A1, Decl(conditionalTypes2.ts, 48, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 50, 13))
bat: B1<A1<T>>;
>bat : Symbol(A1.bat, Decl(conditionalTypes2.ts, 50, 17))
>B1 : Symbol(B1, Decl(conditionalTypes2.ts, 52, 1))
>A1 : Symbol(A1, Decl(conditionalTypes2.ts, 48, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 50, 13))
}
interface B1<T> extends A1<T> {
>B1 : Symbol(B1, Decl(conditionalTypes2.ts, 52, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 54, 13))
>A1 : Symbol(A1, Decl(conditionalTypes2.ts, 48, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 54, 13))
bat: B1<B1<T>>;
>bat : Symbol(B1.bat, Decl(conditionalTypes2.ts, 54, 31))
>B1 : Symbol(B1, Decl(conditionalTypes2.ts, 52, 1))
>B1 : Symbol(B1, Decl(conditionalTypes2.ts, 52, 1))
>T : Symbol(T, Decl(conditionalTypes2.ts, 54, 13))
boom: T extends any ? true : true
>boom : Symbol(B1.boom, Decl(conditionalTypes2.ts, 55, 19))
>T : Symbol(T, Decl(conditionalTypes2.ts, 54, 13))
}

View File

@@ -0,0 +1,218 @@
=== tests/cases/conformance/types/conditional/conditionalTypes2.ts ===
interface Covariant<T> {
>Covariant : Covariant<T>
>T : T
foo: T extends string ? T : number;
>foo : T extends string ? T : number
>T : T
>T : T
}
interface Contravariant<T> {
>Contravariant : Contravariant<T>
>T : T
foo: T extends string ? keyof T : number;
>foo : T extends string ? keyof T : number
>T : T
>T : T
}
interface Invariant<T> {
>Invariant : Invariant<T>
>T : T
foo: T extends string ? keyof T : T;
>foo : T extends string ? keyof T : T
>T : T
>T : T
>T : T
}
function f1<A, B extends A>(a: Covariant<A>, b: Covariant<B>) {
>f1 : <A, B extends A>(a: Covariant<A>, b: Covariant<B>) => void
>A : A
>B : B
>A : A
>a : Covariant<A>
>Covariant : Covariant<T>
>A : A
>b : Covariant<B>
>Covariant : Covariant<T>
>B : B
a = b;
>a = b : Covariant<B>
>a : Covariant<A>
>b : Covariant<B>
b = a; // Error
>b = a : Covariant<A>
>b : Covariant<B>
>a : Covariant<A>
}
function f2<A, B extends A>(a: Contravariant<A>, b: Contravariant<B>) {
>f2 : <A, B extends A>(a: Contravariant<A>, b: Contravariant<B>) => void
>A : A
>B : B
>A : A
>a : Contravariant<A>
>Contravariant : Contravariant<T>
>A : A
>b : Contravariant<B>
>Contravariant : Contravariant<T>
>B : B
a = b; // Error
>a = b : Contravariant<B>
>a : Contravariant<A>
>b : Contravariant<B>
b = a;
>b = a : Contravariant<A>
>b : Contravariant<B>
>a : Contravariant<A>
}
function f3<A, B extends A>(a: Invariant<A>, b: Invariant<B>) {
>f3 : <A, B extends A>(a: Invariant<A>, b: Invariant<B>) => void
>A : A
>B : B
>A : A
>a : Invariant<A>
>Invariant : Invariant<T>
>A : A
>b : Invariant<B>
>Invariant : Invariant<T>
>B : B
a = b; // Error
>a = b : Invariant<B>
>a : Invariant<A>
>b : Invariant<B>
b = a; // Error
>b = a : Invariant<A>
>b : Invariant<B>
>a : Invariant<A>
}
// Repros from #22860
class Opt<T> {
>Opt : Opt<T>
>T : T
toVector(): Vector<T> {
>toVector : () => Vector<T>
>Vector : Vector<T>
>T : T
return <any>undefined;
><any>undefined : any
>undefined : undefined
}
}
interface Seq<T> {
>Seq : Seq<T>
>T : T
tail(): Opt<Seq<T>>;
>tail : () => Opt<Seq<T>>
>Opt : Opt<T>
>Seq : Seq<T>
>T : T
}
class Vector<T> implements Seq<T> {
>Vector : Vector<T>
>T : T
>Seq : Seq<T>
>T : T
tail(): Opt<Vector<T>> {
>tail : () => Opt<Vector<T>>
>Opt : Opt<T>
>Vector : Vector<T>
>T : T
return <any>undefined;
><any>undefined : any
>undefined : undefined
}
partition2<U extends T>(predicate:(v:T)=>v is U): [Vector<U>,Vector<Exclude<T, U>>];
>partition2 : { <U extends T>(predicate: (v: T) => v is U): [Vector<U>, Vector<Exclude<T, U>>]; (predicate: (x: T) => boolean): [Vector<T>, Vector<T>]; }
>U : U
>T : T
>predicate : (v: T) => v is U
>v : T
>T : T
>v : any
>U : U
>Vector : Vector<T>
>U : U
>Vector : Vector<T>
>Exclude : Exclude<T, U>
>T : T
>U : U
partition2(predicate:(x:T)=>boolean): [Vector<T>,Vector<T>];
>partition2 : { <U extends T>(predicate: (v: T) => v is U): [Vector<U>, Vector<Exclude<T, U>>]; (predicate: (x: T) => boolean): [Vector<T>, Vector<T>]; }
>predicate : (x: T) => boolean
>x : T
>T : T
>Vector : Vector<T>
>T : T
>Vector : Vector<T>
>T : T
partition2<U extends T>(predicate:(v:T)=>boolean): [Vector<U>,Vector<any>] {
>partition2 : { <U extends T>(predicate: (v: T) => v is U): [Vector<U>, Vector<Exclude<T, U>>]; (predicate: (x: T) => boolean): [Vector<T>, Vector<T>]; }
>U : U
>T : T
>predicate : (v: T) => boolean
>v : T
>T : T
>Vector : Vector<T>
>U : U
>Vector : Vector<T>
return <any>undefined;
><any>undefined : any
>undefined : undefined
}
}
interface A1<T> {
>A1 : A1<T>
>T : T
bat: B1<A1<T>>;
>bat : B1<A1<T>>
>B1 : B1<T>
>A1 : A1<T>
>T : T
}
interface B1<T> extends A1<T> {
>B1 : B1<T>
>T : T
>A1 : A1<T>
>T : T
bat: B1<B1<T>>;
>bat : B1<B1<T>>
>B1 : B1<T>
>B1 : B1<T>
>T : T
boom: T extends any ? true : true
>boom : T extends any ? true : true
>T : T
>true : true
>true : true
}

View File

@@ -0,0 +1,20 @@
//// [destructuringWithConstraint.ts]
// Repro from #22823
interface Props {
foo?: boolean;
}
function foo<P extends Props>(props: Readonly<P>) {
let { foo = false } = props;
if (foo === true) { }
}
//// [destructuringWithConstraint.js]
"use strict";
// Repro from #22823
function foo(props) {
var _a = props.foo, foo = _a === void 0 ? false : _a;
if (foo === true) { }
}

View File

@@ -0,0 +1,26 @@
=== tests/cases/compiler/destructuringWithConstraint.ts ===
// Repro from #22823
interface Props {
>Props : Symbol(Props, Decl(destructuringWithConstraint.ts, 0, 0))
foo?: boolean;
>foo : Symbol(Props.foo, Decl(destructuringWithConstraint.ts, 2, 17))
}
function foo<P extends Props>(props: Readonly<P>) {
>foo : Symbol(foo, Decl(destructuringWithConstraint.ts, 4, 1))
>P : Symbol(P, Decl(destructuringWithConstraint.ts, 6, 13))
>Props : Symbol(Props, Decl(destructuringWithConstraint.ts, 0, 0))
>props : Symbol(props, Decl(destructuringWithConstraint.ts, 6, 30))
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
>P : Symbol(P, Decl(destructuringWithConstraint.ts, 6, 13))
let { foo = false } = props;
>foo : Symbol(foo, Decl(destructuringWithConstraint.ts, 7, 9))
>props : Symbol(props, Decl(destructuringWithConstraint.ts, 6, 30))
if (foo === true) { }
>foo : Symbol(foo, Decl(destructuringWithConstraint.ts, 7, 9))
}

View File

@@ -0,0 +1,29 @@
=== tests/cases/compiler/destructuringWithConstraint.ts ===
// Repro from #22823
interface Props {
>Props : Props
foo?: boolean;
>foo : boolean | undefined
}
function foo<P extends Props>(props: Readonly<P>) {
>foo : <P extends Props>(props: Readonly<P>) => void
>P : P
>Props : Props
>props : Readonly<P>
>Readonly : Readonly<T>
>P : P
let { foo = false } = props;
>foo : boolean
>false : false
>props : Readonly<P>
if (foo === true) { }
>foo === true : boolean
>foo : boolean
>true : true
}

View File

@@ -0,0 +1,12 @@
// @strict: true
// Repro from #22823
interface Props {
foo?: boolean;
}
function foo<P extends Props>(props: Readonly<P>) {
let { foo = false } = props;
if (foo === true) { }
}

View File

@@ -0,0 +1,61 @@
// @strict: true
// @declaration: true
interface Covariant<T> {
foo: T extends string ? T : number;
}
interface Contravariant<T> {
foo: T extends string ? keyof T : number;
}
interface Invariant<T> {
foo: T extends string ? keyof T : T;
}
function f1<A, B extends A>(a: Covariant<A>, b: Covariant<B>) {
a = b;
b = a; // Error
}
function f2<A, B extends A>(a: Contravariant<A>, b: Contravariant<B>) {
a = b; // Error
b = a;
}
function f3<A, B extends A>(a: Invariant<A>, b: Invariant<B>) {
a = b; // Error
b = a; // Error
}
// Repros from #22860
class Opt<T> {
toVector(): Vector<T> {
return <any>undefined;
}
}
interface Seq<T> {
tail(): Opt<Seq<T>>;
}
class Vector<T> implements Seq<T> {
tail(): Opt<Vector<T>> {
return <any>undefined;
}
partition2<U extends T>(predicate:(v:T)=>v is U): [Vector<U>,Vector<Exclude<T, U>>];
partition2(predicate:(x:T)=>boolean): [Vector<T>,Vector<T>];
partition2<U extends T>(predicate:(v:T)=>boolean): [Vector<U>,Vector<any>] {
return <any>undefined;
}
}
interface A1<T> {
bat: B1<A1<T>>;
}
interface B1<T> extends A1<T> {
bat: B1<B1<T>>;
boom: T extends any ? true : true
}

View File

@@ -0,0 +1,5 @@
/// <reference path='fourslash.ts' />
////await a
verify.not.codeFixAvailable();

View File

@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts'/>
////
//// }/**/
////
goTo.marker();
verify.not.completionListIsEmpty();