Remove diagnostic dependent output in structuredTypeRelatedTo (#29817)

* Unify variance probing error exceptions between interfaces/aliases

* Consistiently return false on variance probe failure

* Remove strictFunctionTypes early bail from getVariances so independent type parameters are correctly measured

* Fix lint, remove now-redundant change from covariant void check function
This commit is contained in:
Wesley Wigham 2019-02-19 11:39:16 -08:00 committed by GitHub
parent 9d9cfaff16
commit eafff75c2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 1564 additions and 107 deletions

View File

@ -12586,6 +12586,7 @@ namespace ts {
let result: Ternary;
let originalErrorInfo: DiagnosticMessageChain | undefined;
let varianceCheckFailed = false;
const saveErrorInfo = errorInfo;
// We limit alias variance probing to only object and conditional types since their alias behavior
@ -12595,11 +12596,10 @@ namespace ts {
source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
!(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
const variances = getAliasVariances(source.aliasSymbol);
if (result = typeArgumentsRelatedTo(source.aliasTypeArguments, target.aliasTypeArguments, variances, reportErrors)) {
return result;
const varianceResult = relateVariances(source.aliasTypeArguments, target.aliasTypeArguments, variances);
if (varianceResult !== undefined) {
return varianceResult;
}
originalErrorInfo = errorInfo;
errorInfo = saveErrorInfo;
}
if (target.flags & TypeFlags.TypeParameter) {
@ -12764,31 +12764,9 @@ namespace ts {
// type references (which are intended by be compared structurally). Obtain the variance
// information for the type parameters and relate the type arguments accordingly.
const variances = getVariances((<TypeReference>source).target);
if (result = typeArgumentsRelatedTo((<TypeReference>source).typeArguments, (<TypeReference>target).typeArguments, variances, reportErrors)) {
return result;
}
// The type arguments did not relate appropriately, but it may be because we have no variance
// information (in which case typeArgumentsRelatedTo defaulted to covariance for all type
// arguments). It might also be the case that the target type has a 'void' type argument for
// a covariant type parameter that is only used in return positions within the generic type
// (in which case any type argument is permitted on the source side). In those cases we proceed
// with a structural comparison. Otherwise, we know for certain the instantiations aren't
// related and we can return here.
if (variances !== emptyArray && !hasCovariantVoidArgument(<TypeReference>target, variances)) {
// In some cases generic types that are covariant in regular type checking mode become
// invariant in --strictFunctionTypes mode because one or more type parameters are used in
// both co- and contravariant positions. In order to make it easier to diagnose *why* such
// types are invariant, if any of the type parameters are invariant we reset the reported
// errors and instead force a structural comparison (which will include elaborations that
// reveal the reason).
if (!(reportErrors && some(variances, v => v === Variance.Invariant))) {
return Ternary.False;
}
// We remember the original error information so we can restore it in case the structural
// comparison unexpectedly succeeds. This can happen when the structural comparison result
// is a Ternary.Maybe for example caused by the recursion depth limiter.
originalErrorInfo = errorInfo;
errorInfo = saveErrorInfo;
const varianceResult = relateVariances((<TypeReference>source).typeArguments, (<TypeReference>target).typeArguments, variances);
if (varianceResult !== undefined) {
return varianceResult;
}
}
else if (isReadonlyArrayType(target) ? isArrayType(source) || isTupleType(source) : isArrayType(target) && isTupleType(source) && !source.target.readonly) {
@ -12815,16 +12793,48 @@ namespace ts {
}
}
}
if (result) {
if (!originalErrorInfo) {
errorInfo = saveErrorInfo;
return result;
}
errorInfo = originalErrorInfo;
if (varianceCheckFailed && result) {
errorInfo = originalErrorInfo || errorInfo || saveErrorInfo; // Use variance error (there is no structural one) and return false
}
else if (result) {
return result;
}
}
}
return Ternary.False;
function relateVariances(sourceTypeArguments: ReadonlyArray<Type> | undefined, targetTypeArguments: ReadonlyArray<Type> | undefined, variances: Variance[]) {
if (result = typeArgumentsRelatedTo(sourceTypeArguments, targetTypeArguments, variances, reportErrors)) {
return result;
}
const isCovariantVoid = targetTypeArguments && hasCovariantVoidArgument(targetTypeArguments, variances);
varianceCheckFailed = !isCovariantVoid;
// The type arguments did not relate appropriately, but it may be because we have no variance
// information (in which case typeArgumentsRelatedTo defaulted to covariance for all type
// arguments). It might also be the case that the target type has a 'void' type argument for
// a covariant type parameter that is only used in return positions within the generic type
// (in which case any type argument is permitted on the source side). In those cases we proceed
// with a structural comparison. Otherwise, we know for certain the instantiations aren't
// related and we can return here.
if (variances !== emptyArray && !isCovariantVoid) {
// In some cases generic types that are covariant in regular type checking mode become
// invariant in --strictFunctionTypes mode because one or more type parameters are used in
// both co- and contravariant positions. In order to make it easier to diagnose *why* such
// types are invariant, if any of the type parameters are invariant we reset the reported
// errors and instead force a structural comparison (which will include elaborations that
// reveal the reason).
// We can switch on `reportErrors` here, since varianceCheckFailed guarantees we return `False`,
// we can return `False` early here to skip calculating the structural error message we don't need.
if (varianceCheckFailed && !(reportErrors && some(variances, v => v === Variance.Invariant))) {
return Ternary.False;
}
// We remember the original error information so we can restore it in case the structural
// comparison unexpectedly succeeds. This can happen when the structural comparison result
// is a Ternary.Maybe for example caused by the recursion depth limiter.
originalErrorInfo = errorInfo;
errorInfo = saveErrorInfo;
}
}
}
// A type [P in S]: X is related to a type [Q in T]: Y if T is related to S and X' is
@ -13333,7 +13343,7 @@ namespace ts {
function getVariances(type: GenericType): Variance[] {
// Arrays and tuples are known to be covariant, no need to spend time computing this (emptyArray implies covariance for all parameters)
if (!strictFunctionTypes || type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
return emptyArray;
}
return getVariancesWorker(type.typeParameters, type, getMarkerTypeReference);
@ -13341,9 +13351,9 @@ namespace ts {
// Return true if the given type reference has a 'void' type argument for a covariant type parameter.
// See comment at call in recursiveTypeRelatedTo for when this case matters.
function hasCovariantVoidArgument(type: TypeReference, variances: Variance[]): boolean {
function hasCovariantVoidArgument(typeArguments: ReadonlyArray<Type>, variances: Variance[]): boolean {
for (let i = 0; i < variances.length; i++) {
if (variances[i] === Variance.Covariant && type.typeArguments![i].flags & TypeFlags.Void) {
if (variances[i] === Variance.Covariant && typeArguments[i].flags & TypeFlags.Void) {
return true;
}
}

View File

@ -0,0 +1,32 @@
tests/cases/compiler/checkInfiniteExpansionTermination.ts(16,1): error TS2322: Type 'ISubject<Bar>' is not assignable to type 'IObservable<Foo>'.
Types of property 'n' are incompatible.
Type 'IObservable<Bar[]>' is not assignable to type 'IObservable<Foo[]>'.
Type 'Bar[]' is not assignable to type 'Foo[]'.
Property 'x' is missing in type 'Bar' but required in type 'Foo'.
==== tests/cases/compiler/checkInfiniteExpansionTermination.ts (1 errors) ====
// Regression test for #1002
// Before fix this code would cause infinite loop
interface IObservable<T> {
n: IObservable<T[]>; // Needed, must be T[]
}
// Needed
interface ISubject<T> extends IObservable<T> { }
interface Foo { x }
interface Bar { y }
var values: IObservable<Foo>;
var values2: ISubject<Bar>;
values = values2;
~~~~~~
!!! error TS2322: Type 'ISubject<Bar>' is not assignable to type 'IObservable<Foo>'.
!!! error TS2322: Types of property 'n' are incompatible.
!!! error TS2322: Type 'IObservable<Bar[]>' is not assignable to type 'IObservable<Foo[]>'.
!!! error TS2322: Type 'Bar[]' is not assignable to type 'Foo[]'.
!!! error TS2322: Property 'x' is missing in type 'Bar' but required in type 'Foo'.
!!! related TS2728 tests/cases/compiler/checkInfiniteExpansionTermination.ts:11:17: 'x' is declared here.

View File

@ -1137,7 +1137,7 @@ declare module Immutable {
>Seq : typeof Seq
function isSeq(maybeSeq: any): maybeSeq is Seq.Indexed<any> | Seq.Keyed<any, any>;
>isSeq : (maybeSeq: any) => maybeSeq is Keyed<any, any> | Indexed<any>
>isSeq : (maybeSeq: any) => maybeSeq is Indexed<any> | Keyed<any, any>
>maybeSeq : any
>Seq : any
>Seq : any

View File

@ -17,8 +17,12 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(103,5): error TS2
tests/cases/conformance/types/conditional/conditionalTypes1.ts(104,5): error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>' is not assignable to type 'T'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(106,5): error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>' is not assignable to type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>'.
Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
Type 'keyof T' is not assignable to type 'never'.
Type 'string | number | symbol' is not assignable to type 'never'.
Type 'string' is not assignable to type 'never'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(108,5): error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>' is not assignable to type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>'.
Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
Type 'keyof T' is not assignable to type 'never'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(114,5): error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
Type 'string' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
@ -183,11 +187,15 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS
~
!!! error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>' is not assignable to type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>'.
!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
!!! error TS2322: Type 'keyof T' is not assignable to type 'never'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'never'.
!!! error TS2322: Type 'string' is not assignable to type 'never'.
z = x;
z = y; // Error
~
!!! error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>' is not assignable to type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>'.
!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
!!! error TS2322: Type 'keyof T' is not assignable to type 'never'.
}
function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {

View File

@ -34,7 +34,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(66,5): error TS2
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(66,5): error TS2542: Index signature in type 'Readonly<U>' only permits reading.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(72,5): error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(78,5): error TS2322: Type 'Partial<Thing>' is not assignable to type 'Partial<T>'.
Type 'Thing' is not assignable to type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(88,5): error TS2322: Type 'Readonly<Thing>' is not assignable to type 'Readonly<T>'.
Type 'Thing' is not assignable to type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(127,5): error TS2322: Type 'Partial<U>' is not assignable to type 'Identity<U>'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(143,5): error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof T]: U[P]; }'.
Type 'T[P]' is not assignable to type 'U[P]'.
@ -197,6 +199,7 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS
y = x; // Error
~
!!! error TS2322: Type 'Partial<Thing>' is not assignable to type 'Partial<T>'.
!!! error TS2322: Type 'Thing' is not assignable to type 'T'.
}
function f40<T>(x: T, y: Readonly<T>) {
@ -209,6 +212,7 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS
y = x; // Error
~
!!! error TS2322: Type 'Readonly<Thing>' is not assignable to type 'Readonly<T>'.
!!! error TS2322: Type 'Thing' is not assignable to type 'T'.
}
type Item = {

View File

@ -1,6 +1,7 @@
tests/cases/conformance/types/mapped/mappedTypes5.ts(6,9): error TS2322: Type 'Partial<T>' is not assignable to type 'Readonly<T>'.
tests/cases/conformance/types/mapped/mappedTypes5.ts(8,9): error TS2322: Type 'Partial<Readonly<T>>' is not assignable to type 'Readonly<T>'.
tests/cases/conformance/types/mapped/mappedTypes5.ts(9,9): error TS2322: Type 'Readonly<Partial<T>>' is not assignable to type 'Readonly<T>'.
Type 'Partial<T>' is not assignable to type 'T'.
==== tests/cases/conformance/types/mapped/mappedTypes5.ts (3 errors) ====
@ -19,6 +20,7 @@ tests/cases/conformance/types/mapped/mappedTypes5.ts(9,9): error TS2322: Type 'R
let b4: Readonly<T> = rp; // Error
~~
!!! error TS2322: Type 'Readonly<Partial<T>>' is not assignable to type 'Readonly<T>'.
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
let c1: Partial<Readonly<T>> = p;
let c2: Partial<Readonly<T>> = r;
let c3: Partial<Readonly<T>> = pr;

View File

@ -0,0 +1,27 @@
tests/cases/compiler/recursiveTypeComparison.ts(14,5): error TS2322: Type 'Observable<{}>' is not assignable to type 'Property<number>'.
Types of property 'needThisOne' are incompatible.
Type 'Observable<{}>' is not assignable to type 'Observable<number>'.
Type '{}' is not assignable to type 'number'.
==== tests/cases/compiler/recursiveTypeComparison.ts (1 errors) ====
// Before fix this would take an exceeding long time to complete (#1170)
interface Observable<T> {
// This member can't be of type T, Property<T>, or Observable<anything but T>
needThisOne: Observable<T>;
// Add more to make it slower
expo1: Property<T[]>; // 0.31 seconds in check
expo2: Property<T[]>; // 3.11 seconds
expo3: Property<T[]>; // 82.28 seconds
}
interface Property<T> extends Observable<T> { }
var p: Observable<{}>;
var stuck: Property<number> = p;
~~~~~
!!! error TS2322: Type 'Observable<{}>' is not assignable to type 'Property<number>'.
!!! error TS2322: Types of property 'needThisOne' are incompatible.
!!! error TS2322: Type 'Observable<{}>' is not assignable to type 'Observable<number>'.
!!! error TS2322: Type '{}' is not assignable to type 'number'.

View File

@ -17,19 +17,15 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(21,1): error TS2322: Type '(x:
tests/cases/compiler/strictFunctionTypesErrors.ts(23,1): error TS2322: Type '(x: string) => Object' is not assignable to type '(x: string) => string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(33,1): error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<Object, Object>'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(34,1): error TS2322: Type 'Func<string, string>' is not assignable to type 'Func<Object, Object>'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(36,1): error TS2322: Type 'Func<Object, Object>' is not assignable to type 'Func<Object, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(37,1): error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<Object, string>'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(38,1): error TS2322: Type 'Func<string, string>' is not assignable to type 'Func<Object, string>'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(44,1): error TS2322: Type 'Func<Object, Object>' is not assignable to type 'Func<string, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(46,1): error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<string, string>'.
@ -39,37 +35,26 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(57,1): error TS2322: Type 'Fun
tests/cases/compiler/strictFunctionTypesErrors.ts(58,1): error TS2322: Type 'Func<Func<string, void>, Object>' is not assignable to type 'Func<Func<Object, void>, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(61,1): error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<string, void>, Object>'.
Types of parameters 'x' and 'x' are incompatible.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(62,1): error TS2322: Type 'Func<Func<Object, void>, string>' is not assignable to type 'Func<Func<string, void>, Object>'.
Types of parameters 'x' and 'x' are incompatible.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(65,1): error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<string, void>, string>'.
Types of parameters 'x' and 'x' are incompatible.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(66,1): error TS2322: Type 'Func<Func<Object, void>, string>' is not assignable to type 'Func<Func<string, void>, string>'.
Types of parameters 'x' and 'x' are incompatible.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(67,1): error TS2322: Type 'Func<Func<string, void>, Object>' is not assignable to type 'Func<Func<string, void>, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(74,1): error TS2322: Type 'Func<Object, Func<string, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(75,1): error TS2322: Type 'Func<string, Func<Object, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(76,1): error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(79,1): error TS2322: Type 'Func<string, Func<Object, void>>' is not assignable to type 'Func<Object, Func<string, void>>'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(80,1): error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<Object, Func<string, void>>'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(83,1): error TS2322: Type 'Func<Object, Func<string, void>>' is not assignable to type 'Func<string, Func<Object, void>>'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(84,1): error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<string, Func<Object, void>>'.
@ -162,13 +147,11 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(155,5): error TS2322: Type '(c
g1 = g3; // Error
~~
!!! error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<Object, Object>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g1 = g4; // Error
~~
!!! error TS2322: Type 'Func<string, string>' is not assignable to type 'Func<Object, Object>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g2 = g1; // Error
~~
@ -177,13 +160,11 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(155,5): error TS2322: Type '(c
g2 = g3; // Error
~~
!!! error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<Object, string>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g2 = g4; // Error
~~
!!! error TS2322: Type 'Func<string, string>' is not assignable to type 'Func<Object, string>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g3 = g1; // Ok
g3 = g2; // Ok
@ -221,29 +202,22 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(155,5): error TS2322: Type '(c
h3 = h1; // Error
~~
!!! error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<string, void>, Object>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
h3 = h2; // Error
~~
!!! error TS2322: Type 'Func<Func<Object, void>, string>' is not assignable to type 'Func<Func<string, void>, Object>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
h3 = h4; // Ok
h4 = h1; // Error
~~
!!! error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<string, void>, string>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
h4 = h2; // Error
~~
!!! error TS2322: Type 'Func<Func<Object, void>, string>' is not assignable to type 'Func<Func<string, void>, string>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
h4 = h3; // Error
~~
!!! error TS2322: Type 'Func<Func<string, void>, Object>' is not assignable to type 'Func<Func<string, void>, string>'.
@ -261,25 +235,21 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(155,5): error TS2322: Type '(c
i1 = i3; // Error
~~
!!! error TS2322: Type 'Func<string, Func<Object, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
i1 = i4; // Error
~~
!!! error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
i2 = i1; // Ok
i2 = i3; // Error
~~
!!! error TS2322: Type 'Func<string, Func<Object, void>>' is not assignable to type 'Func<Object, Func<string, void>>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
i2 = i4; // Error
~~
!!! error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<Object, Func<string, void>>'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
i3 = i1; // Ok
i3 = i2; // Error

View File

@ -9,16 +9,13 @@ tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(27,1): error TS2322: Typ
Property 'kwah' is missing in type 'Foo' but required in type 'Kwah'.
tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(48,1): error TS2322: Type 'X<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'.
Type 'X<Foo>' is not assignable to type 'X<Bar>'.
Types of property 'xProp' are incompatible.
Type 'Foo' is not assignable to type 'Bar'.
Type 'Foo' is not assignable to type 'Bar'.
tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(49,1): error TS2322: Type 'Y<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'.
Type 'Y<Foo>' is not assignable to type 'Y<Baz>'.
Types of property 'yProp' are incompatible.
Type 'Foo' is not assignable to type 'Baz'.
Type 'Foo' is not assignable to type 'Baz'.
tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(50,1): error TS2322: Type 'Z<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'.
Type 'Z<Foo>' is not assignable to type 'Z<Kwah>'.
Types of property 'zProp' are incompatible.
Type 'Foo' is not assignable to type 'Kwah'.
Type 'Foo' is not assignable to type 'Kwah'.
==== tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts (6 errors) ====
@ -88,17 +85,14 @@ tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(50,1): error TS2322: Typ
~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'X<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'.
!!! error TS2322: Type 'X<Foo>' is not assignable to type 'X<Bar>'.
!!! error TS2322: Types of property 'xProp' are incompatible.
!!! error TS2322: Type 'Foo' is not assignable to type 'Bar'.
!!! error TS2322: Type 'Foo' is not assignable to type 'Bar'.
thingOfTypeAliases = y;
~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'Y<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'.
!!! error TS2322: Type 'Y<Foo>' is not assignable to type 'Y<Baz>'.
!!! error TS2322: Types of property 'yProp' are incompatible.
!!! error TS2322: Type 'Foo' is not assignable to type 'Baz'.
!!! error TS2322: Type 'Foo' is not assignable to type 'Baz'.
thingOfTypeAliases = z;
~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'Z<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'.
!!! error TS2322: Type 'Z<Foo>' is not assignable to type 'Z<Kwah>'.
!!! error TS2322: Types of property 'zProp' are incompatible.
!!! error TS2322: Type 'Foo' is not assignable to type 'Kwah'.
!!! error TS2322: Type 'Foo' is not assignable to type 'Kwah'.

View File

@ -0,0 +1,82 @@
tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts(63,6): error TS2345: Argument of type 'NeededInfo<ToB<{ initialize: any; }>>' is not assignable to parameter of type 'NeededInfo<{}>'.
Types of property 'ASchema' are incompatible.
Type 'ToA<ToB<{ initialize: any; }>>' is not assignable to type 'ToA<{}>'.
Type '{}' is not assignable to type 'ToB<{ initialize: any; }>'.
tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts(66,38): error TS2344: Type 'NeededInfo<ToB<{ initialize: any; }>>' does not satisfy the constraint 'NeededInfo<{}>'.
==== tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts (2 errors) ====
type Either<L, A> = Left<L, A> | Right<L, A>;
class Left<L, A> {
readonly _tag: 'Left' = 'Left'
readonly _A!: A
readonly _L!: L
constructor(readonly value: L) {}
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
return this as any
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any
}
}
class Right<L, A> {
readonly _tag: 'Right' = 'Right'
readonly _A!: A
readonly _L!: L
constructor(readonly value: A) {}
map<B>(f: (a: A) => B): Either<L, B> {
return new Right(f(this.value))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any;
}
}
class Type<A, O = A, I = unknown> {
readonly _A!: A;
readonly _O!: O;
readonly _I!: I;
constructor(
/** a unique name for this codec */
readonly name: string,
/** a custom type guard */
readonly is: (u: unknown) => u is A,
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
}
interface Any extends Type<any, any, any> {}
type TypeOf<C extends Any> = C["_A"];
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
type ToA<S> = { [k in keyof S]: Type<S[k]> };
type NeededInfo<MyNamespaceSchema = {}> = {
ASchema: ToA<MyNamespaceSchema>;
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
const tmp1: MyInfo = null!;
function tmp2<N extends NeededInfo>(n: N) {}
tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ??
~~~~
!!! error TS2345: Argument of type 'NeededInfo<ToB<{ initialize: any; }>>' is not assignable to parameter of type 'NeededInfo<{}>'.
!!! error TS2345: Types of property 'ASchema' are incompatible.
!!! error TS2345: Type 'ToA<ToB<{ initialize: any; }>>' is not assignable to type 'ToA<{}>'.
!!! error TS2345: Type '{}' is not assignable to type 'ToB<{ initialize: any; }>'.
!!! related TS2728 tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts:59:39: 'initialize' is declared here.
class Server<X extends NeededInfo> {}
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`
~~~~~~
!!! error TS2344: Type 'NeededInfo<ToB<{ initialize: any; }>>' does not satisfy the constraint 'NeededInfo<{}>'.

View File

@ -0,0 +1,146 @@
//// [varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts]
type Either<L, A> = Left<L, A> | Right<L, A>;
class Left<L, A> {
readonly _tag: 'Left' = 'Left'
readonly _A!: A
readonly _L!: L
constructor(readonly value: L) {}
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
return this as any
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any
}
}
class Right<L, A> {
readonly _tag: 'Right' = 'Right'
readonly _A!: A
readonly _L!: L
constructor(readonly value: A) {}
map<B>(f: (a: A) => B): Either<L, B> {
return new Right(f(this.value))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any;
}
}
class Type<A, O = A, I = unknown> {
readonly _A!: A;
readonly _O!: O;
readonly _I!: I;
constructor(
/** a unique name for this codec */
readonly name: string,
/** a custom type guard */
readonly is: (u: unknown) => u is A,
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
}
interface Any extends Type<any, any, any> {}
type TypeOf<C extends Any> = C["_A"];
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
type ToA<S> = { [k in keyof S]: Type<S[k]> };
type NeededInfo<MyNamespaceSchema = {}> = {
ASchema: ToA<MyNamespaceSchema>;
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
const tmp1: MyInfo = null!;
function tmp2<N extends NeededInfo>(n: N) {}
tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ??
class Server<X extends NeededInfo> {}
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`
//// [varianceProblingAndZeroOrderIndexSignatureRelationsAlign.js]
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var Left = /** @class */ (function () {
function Left(value) {
this.value = value;
this._tag = 'Left';
}
/** The given function is applied if this is a `Right` */
Left.prototype.map = function (f) {
return this;
};
Left.prototype.ap = function (fab) {
return null;
};
return Left;
}());
var Right = /** @class */ (function () {
function Right(value) {
this.value = value;
this._tag = 'Right';
}
Right.prototype.map = function (f) {
return new Right(f(this.value));
};
Right.prototype.ap = function (fab) {
return null;
};
return Right;
}());
var Type = /** @class */ (function () {
function Type(
/** a unique name for this codec */
name,
/** a custom type guard */
is,
/** succeeds if a value of type I can be decoded to a value of type A */
validate,
/** converts a value of type A to a value of type O */
encode) {
this.name = name;
this.is = is;
this.validate = validate;
this.encode = encode;
}
/** a version of `validate` with a default context */
Type.prototype.decode = function (i) { return null; };
return Type;
}());
var tmp1 = null;
function tmp2(n) { }
tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ??
var Server = /** @class */ (function () {
function Server() {
}
return Server;
}());
var MyServer = /** @class */ (function (_super) {
__extends(MyServer, _super);
function MyServer() {
return _super !== null && _super.apply(this, arguments) || this;
}
return MyServer;
}(Server)); // not assignable error at `MyInfo`
exports.MyServer = MyServer;

View File

@ -0,0 +1,246 @@
=== tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts ===
type Either<L, A> = Left<L, A> | Right<L, A>;
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 12))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 14))
>Left : Symbol(Left, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 45))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 12))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 14))
>Right : Symbol(Right, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 14, 1))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 12))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 14))
class Left<L, A> {
>Left : Symbol(Left, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 45))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 11))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 13))
readonly _tag: 'Left' = 'Left'
>_tag : Symbol(Left._tag, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 18))
readonly _A!: A
>_A : Symbol(Left._A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 3, 34))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 13))
readonly _L!: L
>_L : Symbol(Left._L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 4, 19))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 11))
constructor(readonly value: L) {}
>value : Symbol(Left.value, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 6, 16))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 11))
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
>map : Symbol(Left.map, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 6, 37))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 8, 8))
>f : Symbol(f, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 8, 11))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 8, 15))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 13))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 8, 8))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 11))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 8, 8))
return this as any
>this : Symbol(Left, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 45))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
>ap : Symbol(Left.ap, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 10, 5))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 11, 7))
>fab : Symbol(fab, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 11, 10))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 11))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 11, 26))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 13))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 11, 7))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 2, 11))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 11, 7))
return null as any
}
}
class Right<L, A> {
>Right : Symbol(Right, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 14, 1))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 12))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 14))
readonly _tag: 'Right' = 'Right'
>_tag : Symbol(Right._tag, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 19))
readonly _A!: A
>_A : Symbol(Right._A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 17, 36))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 14))
readonly _L!: L
>_L : Symbol(Right._L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 18, 19))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 12))
constructor(readonly value: A) {}
>value : Symbol(Right.value, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 20, 16))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 14))
map<B>(f: (a: A) => B): Either<L, B> {
>map : Symbol(Right.map, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 20, 37))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 21, 8))
>f : Symbol(f, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 21, 11))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 21, 15))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 14))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 21, 8))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 12))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 21, 8))
return new Right(f(this.value))
>Right : Symbol(Right, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 14, 1))
>f : Symbol(f, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 21, 11))
>this.value : Symbol(Right.value, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 20, 16))
>this : Symbol(Right, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 14, 1))
>value : Symbol(Right.value, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 20, 16))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
>ap : Symbol(Right.ap, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 23, 5))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 24, 7))
>fab : Symbol(fab, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 24, 10))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 12))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 24, 26))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 14))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 24, 7))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 16, 12))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 24, 7))
return null as any;
}
}
class Type<A, O = A, I = unknown> {
>Type : Symbol(Type, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 27, 1))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 11))
>O : Symbol(O, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 13))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 11))
>I : Symbol(I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 20))
readonly _A!: A;
>_A : Symbol(Type._A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 35))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 11))
readonly _O!: O;
>_O : Symbol(Type._O, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 30, 18))
>O : Symbol(O, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 13))
readonly _I!: I;
>_I : Symbol(Type._I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 31, 18))
>I : Symbol(I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 20))
constructor(
/** a unique name for this codec */
readonly name: string,
>name : Symbol(Type.name, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 33, 14))
/** a custom type guard */
readonly is: (u: unknown) => u is A,
>is : Symbol(Type.is, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 35, 26))
>u : Symbol(u, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 37, 18))
>u : Symbol(u, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 37, 18))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 11))
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
>validate : Symbol(Type.validate, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 37, 40))
>input : Symbol(input, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 39, 24))
>I : Symbol(I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 20))
>context : Symbol(context, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 39, 33))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 0))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 11))
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
>encode : Symbol(Type.encode, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 39, 68))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 41, 22))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 11))
>O : Symbol(O, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 13))
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
>decode : Symbol(Type.decode, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 42, 6))
>i : Symbol(i, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 44, 9))
>I : Symbol(I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 20))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 0, 0))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 29, 11))
}
interface Any extends Type<any, any, any> {}
>Any : Symbol(Any, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 45, 1))
>Type : Symbol(Type, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 27, 1))
type TypeOf<C extends Any> = C["_A"];
>TypeOf : Symbol(TypeOf, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 47, 44))
>C : Symbol(C, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 49, 12))
>Any : Symbol(Any, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 45, 1))
>C : Symbol(C, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 49, 12))
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
>ToB : Symbol(ToB, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 49, 37))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 51, 9))
>k : Symbol(k, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 51, 29))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 51, 9))
>TypeOf : Symbol(TypeOf, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 47, 44))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 51, 9))
>k : Symbol(k, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 51, 29))
type ToA<S> = { [k in keyof S]: Type<S[k]> };
>ToA : Symbol(ToA, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 51, 59))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 52, 9))
>k : Symbol(k, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 52, 17))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 52, 9))
>Type : Symbol(Type, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 27, 1))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 52, 9))
>k : Symbol(k, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 52, 17))
type NeededInfo<MyNamespaceSchema = {}> = {
>NeededInfo : Symbol(NeededInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 52, 45))
>MyNamespaceSchema : Symbol(MyNamespaceSchema, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 54, 16))
ASchema: ToA<MyNamespaceSchema>;
>ASchema : Symbol(ASchema, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 54, 43))
>ToA : Symbol(ToA, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 51, 59))
>MyNamespaceSchema : Symbol(MyNamespaceSchema, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 54, 16))
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
>MyInfo : Symbol(MyInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 56, 2))
>NeededInfo : Symbol(NeededInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 52, 45))
>ToB : Symbol(ToB, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 49, 37))
>initialize : Symbol(initialize, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 58, 37))
const tmp1: MyInfo = null!;
>tmp1 : Symbol(tmp1, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 60, 5))
>MyInfo : Symbol(MyInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 56, 2))
function tmp2<N extends NeededInfo>(n: N) {}
>tmp2 : Symbol(tmp2, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 60, 27))
>N : Symbol(N, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 61, 14))
>NeededInfo : Symbol(NeededInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 52, 45))
>n : Symbol(n, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 61, 36))
>N : Symbol(N, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 61, 14))
tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ??
>tmp2 : Symbol(tmp2, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 60, 27))
>tmp1 : Symbol(tmp1, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 60, 5))
class Server<X extends NeededInfo> {}
>Server : Symbol(Server, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 62, 11))
>X : Symbol(X, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 64, 13))
>NeededInfo : Symbol(NeededInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 52, 45))
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`
>MyServer : Symbol(MyServer, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 64, 37))
>Server : Symbol(Server, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 62, 11))
>MyInfo : Symbol(MyInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts, 56, 2))

View File

@ -0,0 +1,168 @@
=== tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts ===
type Either<L, A> = Left<L, A> | Right<L, A>;
>Either : Either<L, A>
class Left<L, A> {
>Left : Left<L, A>
readonly _tag: 'Left' = 'Left'
>_tag : "Left"
>'Left' : "Left"
readonly _A!: A
>_A : A
readonly _L!: L
>_L : L
constructor(readonly value: L) {}
>value : L
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
>map : <B>(f: (a: A) => B) => Either<L, B>
>f : (a: A) => B
>a : A
return this as any
>this as any : any
>this : this
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
>ap : <B>(fab: Either<L, (a: A) => B>) => Either<L, B>
>fab : Either<L, (a: A) => B>
>a : A
return null as any
>null as any : any
>null : null
}
}
class Right<L, A> {
>Right : Right<L, A>
readonly _tag: 'Right' = 'Right'
>_tag : "Right"
>'Right' : "Right"
readonly _A!: A
>_A : A
readonly _L!: L
>_L : L
constructor(readonly value: A) {}
>value : A
map<B>(f: (a: A) => B): Either<L, B> {
>map : <B>(f: (a: A) => B) => Either<L, B>
>f : (a: A) => B
>a : A
return new Right(f(this.value))
>new Right(f(this.value)) : Right<L, B>
>Right : typeof Right
>f(this.value) : B
>f : (a: A) => B
>this.value : A
>this : this
>value : A
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
>ap : <B>(fab: Either<L, (a: A) => B>) => Either<L, B>
>fab : Either<L, (a: A) => B>
>a : A
return null as any;
>null as any : any
>null : null
}
}
class Type<A, O = A, I = unknown> {
>Type : Type<A, O, I>
readonly _A!: A;
>_A : A
readonly _O!: O;
>_O : O
readonly _I!: I;
>_I : I
constructor(
/** a unique name for this codec */
readonly name: string,
>name : string
/** a custom type guard */
readonly is: (u: unknown) => u is A,
>is : (u: unknown) => u is A
>u : unknown
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
>validate : (input: I, context: {}[]) => Either<{}[], A>
>input : I
>context : {}[]
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
>encode : (a: A) => O
>a : A
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
>decode : (i: I) => Either<{}[], A>
>i : I
>null as any : any
>null : null
}
interface Any extends Type<any, any, any> {}
type TypeOf<C extends Any> = C["_A"];
>TypeOf : C["_A"]
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
>ToB : ToB<S>
type ToA<S> = { [k in keyof S]: Type<S[k]> };
>ToA : ToA<S>
type NeededInfo<MyNamespaceSchema = {}> = {
>NeededInfo : NeededInfo<MyNamespaceSchema>
ASchema: ToA<MyNamespaceSchema>;
>ASchema : ToA<MyNamespaceSchema>
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
>MyInfo : NeededInfo<ToB<{ initialize: any; }>>
>initialize : any
const tmp1: MyInfo = null!;
>tmp1 : NeededInfo<ToB<{ initialize: any; }>>
>null! : never
>null : null
function tmp2<N extends NeededInfo>(n: N) {}
>tmp2 : <N extends NeededInfo<{}>>(n: N) => void
>n : N
tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ??
>tmp2(tmp1) : any
>tmp2 : <N extends NeededInfo<{}>>(n: N) => void
>tmp1 : NeededInfo<ToB<{ initialize: any; }>>
class Server<X extends NeededInfo> {}
>Server : Server<X>
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`
>MyServer : MyServer
>Server : Server<NeededInfo<ToB<{ initialize: any; }>>>

View File

@ -0,0 +1,79 @@
tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts(66,38): error TS2344: Type 'NeededInfo<ToB<{ initialize: any; }>>' does not satisfy the constraint 'NeededInfo<{}>'.
Types of property 'ASchema' are incompatible.
Type 'ToA<ToB<{ initialize: any; }>>' is not assignable to type 'ToA<{}>'.
Type '{}' is not assignable to type 'ToB<{ initialize: any; }>'.
==== tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts (1 errors) ====
type Either<L, A> = Left<L, A> | Right<L, A>;
class Left<L, A> {
readonly _tag: 'Left' = 'Left'
readonly _A!: A
readonly _L!: L
constructor(readonly value: L) {}
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
return this as any
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any
}
}
class Right<L, A> {
readonly _tag: 'Right' = 'Right'
readonly _A!: A
readonly _L!: L
constructor(readonly value: A) {}
map<B>(f: (a: A) => B): Either<L, B> {
return new Right(f(this.value))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any;
}
}
class Type<A, O = A, I = unknown> {
readonly _A!: A;
readonly _O!: O;
readonly _I!: I;
constructor(
/** a unique name for this codec */
readonly name: string,
/** a custom type guard */
readonly is: (u: unknown) => u is A,
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
}
interface Any extends Type<any, any, any> {}
type TypeOf<C extends Any> = C["_A"];
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
type ToA<S> = { [k in keyof S]: Type<S[k]> };
type NeededInfo<MyNamespaceSchema = {}> = {
ASchema: ToA<MyNamespaceSchema>;
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
const tmp1: MyInfo = null!;
function tmp2<N extends NeededInfo>(n: N) {}
// tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? (see test 1, needs to behave the same)
class Server<X extends NeededInfo> {}
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`
~~~~~~
!!! error TS2344: Type 'NeededInfo<ToB<{ initialize: any; }>>' does not satisfy the constraint 'NeededInfo<{}>'.
!!! error TS2344: Types of property 'ASchema' are incompatible.
!!! error TS2344: Type 'ToA<ToB<{ initialize: any; }>>' is not assignable to type 'ToA<{}>'.
!!! error TS2344: Type '{}' is not assignable to type 'ToB<{ initialize: any; }>'.
!!! related TS2728 tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts:59:39: 'initialize' is declared here.

View File

@ -0,0 +1,146 @@
//// [varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts]
type Either<L, A> = Left<L, A> | Right<L, A>;
class Left<L, A> {
readonly _tag: 'Left' = 'Left'
readonly _A!: A
readonly _L!: L
constructor(readonly value: L) {}
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
return this as any
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any
}
}
class Right<L, A> {
readonly _tag: 'Right' = 'Right'
readonly _A!: A
readonly _L!: L
constructor(readonly value: A) {}
map<B>(f: (a: A) => B): Either<L, B> {
return new Right(f(this.value))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any;
}
}
class Type<A, O = A, I = unknown> {
readonly _A!: A;
readonly _O!: O;
readonly _I!: I;
constructor(
/** a unique name for this codec */
readonly name: string,
/** a custom type guard */
readonly is: (u: unknown) => u is A,
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
}
interface Any extends Type<any, any, any> {}
type TypeOf<C extends Any> = C["_A"];
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
type ToA<S> = { [k in keyof S]: Type<S[k]> };
type NeededInfo<MyNamespaceSchema = {}> = {
ASchema: ToA<MyNamespaceSchema>;
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
const tmp1: MyInfo = null!;
function tmp2<N extends NeededInfo>(n: N) {}
// tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? (see test 1, needs to behave the same)
class Server<X extends NeededInfo> {}
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`
//// [varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.js]
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var Left = /** @class */ (function () {
function Left(value) {
this.value = value;
this._tag = 'Left';
}
/** The given function is applied if this is a `Right` */
Left.prototype.map = function (f) {
return this;
};
Left.prototype.ap = function (fab) {
return null;
};
return Left;
}());
var Right = /** @class */ (function () {
function Right(value) {
this.value = value;
this._tag = 'Right';
}
Right.prototype.map = function (f) {
return new Right(f(this.value));
};
Right.prototype.ap = function (fab) {
return null;
};
return Right;
}());
var Type = /** @class */ (function () {
function Type(
/** a unique name for this codec */
name,
/** a custom type guard */
is,
/** succeeds if a value of type I can be decoded to a value of type A */
validate,
/** converts a value of type A to a value of type O */
encode) {
this.name = name;
this.is = is;
this.validate = validate;
this.encode = encode;
}
/** a version of `validate` with a default context */
Type.prototype.decode = function (i) { return null; };
return Type;
}());
var tmp1 = null;
function tmp2(n) { }
// tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? (see test 1, needs to behave the same)
var Server = /** @class */ (function () {
function Server() {
}
return Server;
}());
var MyServer = /** @class */ (function (_super) {
__extends(MyServer, _super);
function MyServer() {
return _super !== null && _super.apply(this, arguments) || this;
}
return MyServer;
}(Server)); // not assignable error at `MyInfo`
exports.MyServer = MyServer;

View File

@ -0,0 +1,244 @@
=== tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts ===
type Either<L, A> = Left<L, A> | Right<L, A>;
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 12))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 14))
>Left : Symbol(Left, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 45))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 12))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 14))
>Right : Symbol(Right, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 14, 1))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 12))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 14))
class Left<L, A> {
>Left : Symbol(Left, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 45))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 11))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 13))
readonly _tag: 'Left' = 'Left'
>_tag : Symbol(Left._tag, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 18))
readonly _A!: A
>_A : Symbol(Left._A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 3, 34))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 13))
readonly _L!: L
>_L : Symbol(Left._L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 4, 19))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 11))
constructor(readonly value: L) {}
>value : Symbol(Left.value, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 6, 16))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 11))
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
>map : Symbol(Left.map, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 6, 37))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 8, 8))
>f : Symbol(f, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 8, 11))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 8, 15))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 13))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 8, 8))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 11))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 8, 8))
return this as any
>this : Symbol(Left, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 45))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
>ap : Symbol(Left.ap, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 10, 5))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 11, 7))
>fab : Symbol(fab, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 11, 10))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 11))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 11, 26))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 13))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 11, 7))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 2, 11))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 11, 7))
return null as any
}
}
class Right<L, A> {
>Right : Symbol(Right, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 14, 1))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 12))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 14))
readonly _tag: 'Right' = 'Right'
>_tag : Symbol(Right._tag, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 19))
readonly _A!: A
>_A : Symbol(Right._A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 17, 36))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 14))
readonly _L!: L
>_L : Symbol(Right._L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 18, 19))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 12))
constructor(readonly value: A) {}
>value : Symbol(Right.value, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 20, 16))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 14))
map<B>(f: (a: A) => B): Either<L, B> {
>map : Symbol(Right.map, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 20, 37))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 21, 8))
>f : Symbol(f, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 21, 11))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 21, 15))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 14))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 21, 8))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 12))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 21, 8))
return new Right(f(this.value))
>Right : Symbol(Right, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 14, 1))
>f : Symbol(f, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 21, 11))
>this.value : Symbol(Right.value, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 20, 16))
>this : Symbol(Right, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 14, 1))
>value : Symbol(Right.value, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 20, 16))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
>ap : Symbol(Right.ap, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 23, 5))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 24, 7))
>fab : Symbol(fab, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 24, 10))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 12))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 24, 26))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 14))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 24, 7))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 0))
>L : Symbol(L, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 16, 12))
>B : Symbol(B, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 24, 7))
return null as any;
}
}
class Type<A, O = A, I = unknown> {
>Type : Symbol(Type, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 27, 1))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 11))
>O : Symbol(O, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 13))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 11))
>I : Symbol(I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 20))
readonly _A!: A;
>_A : Symbol(Type._A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 35))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 11))
readonly _O!: O;
>_O : Symbol(Type._O, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 30, 18))
>O : Symbol(O, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 13))
readonly _I!: I;
>_I : Symbol(Type._I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 31, 18))
>I : Symbol(I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 20))
constructor(
/** a unique name for this codec */
readonly name: string,
>name : Symbol(Type.name, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 33, 14))
/** a custom type guard */
readonly is: (u: unknown) => u is A,
>is : Symbol(Type.is, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 35, 26))
>u : Symbol(u, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 37, 18))
>u : Symbol(u, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 37, 18))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 11))
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
>validate : Symbol(Type.validate, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 37, 40))
>input : Symbol(input, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 39, 24))
>I : Symbol(I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 20))
>context : Symbol(context, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 39, 33))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 0))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 11))
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
>encode : Symbol(Type.encode, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 39, 68))
>a : Symbol(a, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 41, 22))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 11))
>O : Symbol(O, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 13))
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
>decode : Symbol(Type.decode, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 42, 6))
>i : Symbol(i, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 44, 9))
>I : Symbol(I, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 20))
>Either : Symbol(Either, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 0, 0))
>A : Symbol(A, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 29, 11))
}
interface Any extends Type<any, any, any> {}
>Any : Symbol(Any, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 45, 1))
>Type : Symbol(Type, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 27, 1))
type TypeOf<C extends Any> = C["_A"];
>TypeOf : Symbol(TypeOf, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 47, 44))
>C : Symbol(C, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 49, 12))
>Any : Symbol(Any, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 45, 1))
>C : Symbol(C, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 49, 12))
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
>ToB : Symbol(ToB, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 49, 37))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 51, 9))
>k : Symbol(k, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 51, 29))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 51, 9))
>TypeOf : Symbol(TypeOf, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 47, 44))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 51, 9))
>k : Symbol(k, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 51, 29))
type ToA<S> = { [k in keyof S]: Type<S[k]> };
>ToA : Symbol(ToA, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 51, 59))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 52, 9))
>k : Symbol(k, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 52, 17))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 52, 9))
>Type : Symbol(Type, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 27, 1))
>S : Symbol(S, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 52, 9))
>k : Symbol(k, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 52, 17))
type NeededInfo<MyNamespaceSchema = {}> = {
>NeededInfo : Symbol(NeededInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 52, 45))
>MyNamespaceSchema : Symbol(MyNamespaceSchema, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 54, 16))
ASchema: ToA<MyNamespaceSchema>;
>ASchema : Symbol(ASchema, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 54, 43))
>ToA : Symbol(ToA, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 51, 59))
>MyNamespaceSchema : Symbol(MyNamespaceSchema, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 54, 16))
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
>MyInfo : Symbol(MyInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 56, 2))
>NeededInfo : Symbol(NeededInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 52, 45))
>ToB : Symbol(ToB, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 49, 37))
>initialize : Symbol(initialize, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 58, 37))
const tmp1: MyInfo = null!;
>tmp1 : Symbol(tmp1, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 60, 5))
>MyInfo : Symbol(MyInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 56, 2))
function tmp2<N extends NeededInfo>(n: N) {}
>tmp2 : Symbol(tmp2, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 60, 27))
>N : Symbol(N, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 61, 14))
>NeededInfo : Symbol(NeededInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 52, 45))
>n : Symbol(n, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 61, 36))
>N : Symbol(N, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 61, 14))
// tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? (see test 1, needs to behave the same)
class Server<X extends NeededInfo> {}
>Server : Symbol(Server, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 61, 44))
>X : Symbol(X, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 64, 13))
>NeededInfo : Symbol(NeededInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 52, 45))
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`
>MyServer : Symbol(MyServer, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 64, 37))
>Server : Symbol(Server, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 61, 44))
>MyInfo : Symbol(MyInfo, Decl(varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts, 56, 2))

View File

@ -0,0 +1,165 @@
=== tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts ===
type Either<L, A> = Left<L, A> | Right<L, A>;
>Either : Either<L, A>
class Left<L, A> {
>Left : Left<L, A>
readonly _tag: 'Left' = 'Left'
>_tag : "Left"
>'Left' : "Left"
readonly _A!: A
>_A : A
readonly _L!: L
>_L : L
constructor(readonly value: L) {}
>value : L
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
>map : <B>(f: (a: A) => B) => Either<L, B>
>f : (a: A) => B
>a : A
return this as any
>this as any : any
>this : this
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
>ap : <B>(fab: Either<L, (a: A) => B>) => Either<L, B>
>fab : Either<L, (a: A) => B>
>a : A
return null as any
>null as any : any
>null : null
}
}
class Right<L, A> {
>Right : Right<L, A>
readonly _tag: 'Right' = 'Right'
>_tag : "Right"
>'Right' : "Right"
readonly _A!: A
>_A : A
readonly _L!: L
>_L : L
constructor(readonly value: A) {}
>value : A
map<B>(f: (a: A) => B): Either<L, B> {
>map : <B>(f: (a: A) => B) => Either<L, B>
>f : (a: A) => B
>a : A
return new Right(f(this.value))
>new Right(f(this.value)) : Right<L, B>
>Right : typeof Right
>f(this.value) : B
>f : (a: A) => B
>this.value : A
>this : this
>value : A
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
>ap : <B>(fab: Either<L, (a: A) => B>) => Either<L, B>
>fab : Either<L, (a: A) => B>
>a : A
return null as any;
>null as any : any
>null : null
}
}
class Type<A, O = A, I = unknown> {
>Type : Type<A, O, I>
readonly _A!: A;
>_A : A
readonly _O!: O;
>_O : O
readonly _I!: I;
>_I : I
constructor(
/** a unique name for this codec */
readonly name: string,
>name : string
/** a custom type guard */
readonly is: (u: unknown) => u is A,
>is : (u: unknown) => u is A
>u : unknown
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
>validate : (input: I, context: {}[]) => Either<{}[], A>
>input : I
>context : {}[]
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
>encode : (a: A) => O
>a : A
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
>decode : (i: I) => Either<{}[], A>
>i : I
>null as any : any
>null : null
}
interface Any extends Type<any, any, any> {}
type TypeOf<C extends Any> = C["_A"];
>TypeOf : C["_A"]
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
>ToB : ToB<S>
type ToA<S> = { [k in keyof S]: Type<S[k]> };
>ToA : ToA<S>
type NeededInfo<MyNamespaceSchema = {}> = {
>NeededInfo : NeededInfo<MyNamespaceSchema>
ASchema: ToA<MyNamespaceSchema>;
>ASchema : ToA<MyNamespaceSchema>
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
>MyInfo : NeededInfo<ToB<{ initialize: any; }>>
>initialize : any
const tmp1: MyInfo = null!;
>tmp1 : NeededInfo<ToB<{ initialize: any; }>>
>null! : never
>null : null
function tmp2<N extends NeededInfo>(n: N) {}
>tmp2 : <N extends NeededInfo<{}>>(n: N) => void
>n : N
// tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? (see test 1, needs to behave the same)
class Server<X extends NeededInfo> {}
>Server : Server<X>
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`
>MyServer : MyServer
>Server : Server<NeededInfo<ToB<{ initialize: any; }>>>

View File

@ -0,0 +1,67 @@
// @strict: true
type Either<L, A> = Left<L, A> | Right<L, A>;
class Left<L, A> {
readonly _tag: 'Left' = 'Left'
readonly _A!: A
readonly _L!: L
constructor(readonly value: L) {}
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
return this as any
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any
}
}
class Right<L, A> {
readonly _tag: 'Right' = 'Right'
readonly _A!: A
readonly _L!: L
constructor(readonly value: A) {}
map<B>(f: (a: A) => B): Either<L, B> {
return new Right(f(this.value))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any;
}
}
class Type<A, O = A, I = unknown> {
readonly _A!: A;
readonly _O!: O;
readonly _I!: I;
constructor(
/** a unique name for this codec */
readonly name: string,
/** a custom type guard */
readonly is: (u: unknown) => u is A,
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
}
interface Any extends Type<any, any, any> {}
type TypeOf<C extends Any> = C["_A"];
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
type ToA<S> = { [k in keyof S]: Type<S[k]> };
type NeededInfo<MyNamespaceSchema = {}> = {
ASchema: ToA<MyNamespaceSchema>;
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
const tmp1: MyInfo = null!;
function tmp2<N extends NeededInfo>(n: N) {}
tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ??
class Server<X extends NeededInfo> {}
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`

View File

@ -0,0 +1,67 @@
// @strict: true
type Either<L, A> = Left<L, A> | Right<L, A>;
class Left<L, A> {
readonly _tag: 'Left' = 'Left'
readonly _A!: A
readonly _L!: L
constructor(readonly value: L) {}
/** The given function is applied if this is a `Right` */
map<B>(f: (a: A) => B): Either<L, B> {
return this as any
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any
}
}
class Right<L, A> {
readonly _tag: 'Right' = 'Right'
readonly _A!: A
readonly _L!: L
constructor(readonly value: A) {}
map<B>(f: (a: A) => B): Either<L, B> {
return new Right(f(this.value))
}
ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> {
return null as any;
}
}
class Type<A, O = A, I = unknown> {
readonly _A!: A;
readonly _O!: O;
readonly _I!: I;
constructor(
/** a unique name for this codec */
readonly name: string,
/** a custom type guard */
readonly is: (u: unknown) => u is A,
/** succeeds if a value of type I can be decoded to a value of type A */
readonly validate: (input: I, context: {}[]) => Either<{}[], A>,
/** converts a value of type A to a value of type O */
readonly encode: (a: A) => O
) {}
/** a version of `validate` with a default context */
decode(i: I): Either<{}[], A> { return null as any; }
}
interface Any extends Type<any, any, any> {}
type TypeOf<C extends Any> = C["_A"];
type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
type ToA<S> = { [k in keyof S]: Type<S[k]> };
type NeededInfo<MyNamespaceSchema = {}> = {
ASchema: ToA<MyNamespaceSchema>;
};
export type MyInfo = NeededInfo<ToB<{ initialize: any }>>;
const tmp1: MyInfo = null!;
function tmp2<N extends NeededInfo>(n: N) {}
// tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? (see test 1, needs to behave the same)
class Server<X extends NeededInfo> {}
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`