mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:00:41 -05:00
Add missing relationship allowing a type to be assignable to a conditional when assignable to both branches (#30639)
* Finally add that missing relationship allowing a type to be assignable to both branches of a conditional * Explicitly write out Ternary.Maybe * Add slightly modified example from #25413 * fix sick sentence * Loosen check to skip false branch constraint check to consider `infer` parameters as always satisfied in the extends clause * Simplify things a bit, only instantiate once Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
@@ -14607,6 +14607,13 @@ namespace ts {
|
||||
return type[cache] = type;
|
||||
}
|
||||
|
||||
function isConditionalTypeAlwaysTrueDisregardingInferTypes(type: ConditionalType) {
|
||||
const extendsInferParamMapper = type.root.inferTypeParameters && createTypeMapper(type.root.inferTypeParameters, map(type.root.inferTypeParameters, () => wildcardType));
|
||||
const checkType = type.checkType;
|
||||
const extendsType = type.extendsType;
|
||||
return isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(instantiateType(extendsType, extendsInferParamMapper)));
|
||||
}
|
||||
|
||||
function getSimplifiedConditionalType(type: ConditionalType, writing: boolean) {
|
||||
const checkType = type.checkType;
|
||||
const extendsType = type.extendsType;
|
||||
@@ -18139,6 +18146,36 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (target.flags & TypeFlags.Conditional) {
|
||||
const c = target as ConditionalType;
|
||||
// Check if the conditional is always true or always false but still deferred for distribution purposes
|
||||
const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType));
|
||||
const skipFalse = !skipTrue && isConditionalTypeAlwaysTrueDisregardingInferTypes(c);
|
||||
|
||||
// Instantiate with a replacement mapper if the conditional is distributive, replacing the check type with a clone of itself,
|
||||
// this way {x: string | number, y: string | number} -> (T extends T ? { x: T, y: T } : never) appropriately _fails_ when
|
||||
// T = string | number (since that will end up distributing and producing `{x: string, y: string} | {x: number, y: number}`,
|
||||
// to which `{x: string | number, y: string | number}` isn't assignable)
|
||||
let distributionMapper: TypeMapper | undefined;
|
||||
const checkVar = getActualTypeVariable(c.root.checkType);
|
||||
if (c.root.isDistributive && checkVar.flags & TypeFlags.TypeParameter) {
|
||||
const newParam = cloneTypeParameter(checkVar);
|
||||
distributionMapper = prependTypeMapping(checkVar, newParam, c.mapper);
|
||||
newParam.mapper = distributionMapper;
|
||||
}
|
||||
|
||||
// TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't)
|
||||
let localResult: Ternary | undefined;
|
||||
if (skipTrue || (localResult = isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.trueType), distributionMapper) : getTrueTypeFromConditionalType(c), /*reportErrors*/ false))) {
|
||||
if (!skipFalse) {
|
||||
localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.falseType), distributionMapper) : getFalseTypeFromConditionalType(c), /*reportErrors*/ false);
|
||||
}
|
||||
}
|
||||
if (localResult) {
|
||||
resetErrorInfo(saveErrorInfo);
|
||||
return localResult;
|
||||
}
|
||||
}
|
||||
else if (target.flags & TypeFlags.TemplateLiteral && source.flags & TypeFlags.StringLiteral) {
|
||||
if (isPatternLiteralType(target)) {
|
||||
// match all non-`string` segments
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(28,20): error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.
|
||||
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(29,21): error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.
|
||||
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(39,3): error TS2322: Type '{ x: T; y: T; }' is not assignable to type 'T extends T ? { x: T; y: T; } : never'.
|
||||
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(46,3): error TS2322: Type 'string' is not assignable to type 'Foo<T>'.
|
||||
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(63,9): error TS2322: Type '{ a: number; b: number; }' is not assignable to type '[T] extends [[infer U]] ? U : { b: number; }'.
|
||||
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(95,23): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Unwrap<this["prop"]>'.
|
||||
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(106,3): error TS2322: Type 'Q' is not assignable to type 'InferBecauseWhyNot<Q>'.
|
||||
Type '(arg: any) => any' is not assignable to type 'InferBecauseWhyNot<Q>'.
|
||||
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(116,3): error TS2322: Type 'Q' is not assignable to type 'InferBecauseWhyNotDistributive<Q>'.
|
||||
Type '(arg: any) => any' is not assignable to type 'InferBecauseWhyNotDistributive<Q>'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts (8 errors) ====
|
||||
export type FilterPropsByType<T, TT> = {
|
||||
[K in keyof T]: T[K] extends TT ? K : never
|
||||
}[keyof T];
|
||||
|
||||
function select<
|
||||
T extends string | number,
|
||||
TList extends object,
|
||||
TValueProp extends FilterPropsByType<TList, T>
|
||||
>(property: T, list: TList[], valueProp: TValueProp) {}
|
||||
|
||||
export function func<XX extends string>(x: XX, tipos: { value: XX }[]) {
|
||||
select(x, tipos, "value");
|
||||
}
|
||||
|
||||
declare function onlyNullablePlease<T extends null extends T ? any : never>(
|
||||
value: T
|
||||
): void;
|
||||
|
||||
declare function onlyNullablePlease2<
|
||||
T extends [null] extends [T] ? any : never
|
||||
>(value: T): void;
|
||||
|
||||
declare var z: string | null;
|
||||
onlyNullablePlease(z); // works as expected
|
||||
onlyNullablePlease2(z); // works as expected
|
||||
|
||||
declare var y: string;
|
||||
onlyNullablePlease(y); // error as expected
|
||||
~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.
|
||||
onlyNullablePlease2(y); // error as expected
|
||||
~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.
|
||||
|
||||
function f<T>(t: T) {
|
||||
var x: T | null = Math.random() > 0.5 ? null : t;
|
||||
onlyNullablePlease(x); // should work
|
||||
onlyNullablePlease2(x); // should work
|
||||
}
|
||||
|
||||
function f2<T>(t1: { x: T; y: T }, t2: T extends T ? { x: T; y: T } : never) {
|
||||
t1 = t2; // OK
|
||||
t2 = t1; // should fail
|
||||
~~
|
||||
!!! error TS2322: Type '{ x: T; y: T; }' is not assignable to type 'T extends T ? { x: T; y: T; } : never'.
|
||||
}
|
||||
|
||||
type Foo<T> = T extends true ? string : "a";
|
||||
|
||||
function test<T>(x: Foo<T>, s: string) {
|
||||
x = "a"; // Currently an error, should be ok
|
||||
x = s; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'Foo<T>'.
|
||||
}
|
||||
|
||||
// #26933
|
||||
type Distributive<T> = T extends { a: number } ? { a: number } : { b: number };
|
||||
function testAssignabilityToConditionalType<T>() {
|
||||
const o = { a: 1, b: 2 };
|
||||
const x: [T] extends [string]
|
||||
? { y: number }
|
||||
: { a: number; b: number } = undefined!;
|
||||
// Simple case: OK
|
||||
const o1: [T] extends [number] ? { a: number } : { b: number } = o;
|
||||
// Simple case where source happens to be a conditional type: also OK
|
||||
const x1: [T] extends [number]
|
||||
? ([T] extends [string] ? { y: number } : { a: number })
|
||||
: ([T] extends [string] ? { y: number } : { b: number }) = x;
|
||||
// Infer type parameters: no good
|
||||
const o2: [T] extends [[infer U]] ? U : { b: number } = o;
|
||||
~~
|
||||
!!! error TS2322: Type '{ a: number; b: number; }' is not assignable to type '[T] extends [[infer U]] ? U : { b: number; }'.
|
||||
|
||||
// The next 4 are arguable - if you choose to ignore the `never` distribution case,
|
||||
// then they're all good. The `never` case _is_ a bit of an outlier - we say distributive types
|
||||
// look approximately like the sum of their branches, but the `never` case bucks that.
|
||||
// There's an argument for the result of dumping `never` into a distributive conditional
|
||||
// being not `never`, but instead the intersection of the branches - a much more precise bound
|
||||
// on that "impossible" input.
|
||||
|
||||
// Distributive where T might instantiate to never: no good
|
||||
const o3: Distributive<T> = o;
|
||||
// Distributive where T & string might instantiate to never: also no good
|
||||
const o4: Distributive<T & string> = o;
|
||||
// Distributive where {a: T} cannot instantiate to never: OK
|
||||
const o5: Distributive<{ a: T }> = o;
|
||||
// Distributive where check type is a conditional which returns a non-never type upon instantiation with `never` but can still return never otherwise: no good
|
||||
const o6: Distributive<[T] extends [never] ? { a: number } : never> = o;
|
||||
}
|
||||
|
||||
type Wrapped<T> = { ___secret: T };
|
||||
type Unwrap<T> = T extends Wrapped<infer U> ? U : T;
|
||||
|
||||
declare function set<T, K extends keyof T>(
|
||||
obj: T,
|
||||
key: K,
|
||||
value: Unwrap<T[K]>
|
||||
): Unwrap<T[K]>;
|
||||
|
||||
class Foo2 {
|
||||
prop!: Wrapped<string>;
|
||||
|
||||
method() {
|
||||
set(this, "prop", "hi"); // <-- type error
|
||||
~~~~
|
||||
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Unwrap<this["prop"]>'.
|
||||
}
|
||||
}
|
||||
|
||||
set(new Foo2(), "prop", "hi"); // <-- typechecks
|
||||
|
||||
type InferBecauseWhyNot<T> = [T] extends [(p: infer P1) => any]
|
||||
? P1 | T
|
||||
: never;
|
||||
|
||||
function f3<Q extends (arg: any) => any>(x: Q): InferBecauseWhyNot<Q> {
|
||||
return x;
|
||||
~~~~~~~~~
|
||||
!!! error TS2322: Type 'Q' is not assignable to type 'InferBecauseWhyNot<Q>'.
|
||||
!!! error TS2322: Type '(arg: any) => any' is not assignable to type 'InferBecauseWhyNot<Q>'.
|
||||
}
|
||||
|
||||
type InferBecauseWhyNotDistributive<T> = T extends (p: infer P1) => any
|
||||
? P1 | T
|
||||
: never;
|
||||
|
||||
function f4<Q extends (arg: any) => any>(
|
||||
x: Q
|
||||
): InferBecauseWhyNotDistributive<Q> {
|
||||
return x; // should fail
|
||||
~~~~~~~~~
|
||||
!!! error TS2322: Type 'Q' is not assignable to type 'InferBecauseWhyNotDistributive<Q>'.
|
||||
!!! error TS2322: Type '(arg: any) => any' is not assignable to type 'InferBecauseWhyNotDistributive<Q>'.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
//// [conditionalTypeAssignabilityWhenDeferred.ts]
|
||||
export type FilterPropsByType<T, TT> = {
|
||||
[K in keyof T]: T[K] extends TT ? K : never
|
||||
}[keyof T];
|
||||
|
||||
function select<
|
||||
T extends string | number,
|
||||
TList extends object,
|
||||
TValueProp extends FilterPropsByType<TList, T>
|
||||
>(property: T, list: TList[], valueProp: TValueProp) {}
|
||||
|
||||
export function func<XX extends string>(x: XX, tipos: { value: XX }[]) {
|
||||
select(x, tipos, "value");
|
||||
}
|
||||
|
||||
declare function onlyNullablePlease<T extends null extends T ? any : never>(
|
||||
value: T
|
||||
): void;
|
||||
|
||||
declare function onlyNullablePlease2<
|
||||
T extends [null] extends [T] ? any : never
|
||||
>(value: T): void;
|
||||
|
||||
declare var z: string | null;
|
||||
onlyNullablePlease(z); // works as expected
|
||||
onlyNullablePlease2(z); // works as expected
|
||||
|
||||
declare var y: string;
|
||||
onlyNullablePlease(y); // error as expected
|
||||
onlyNullablePlease2(y); // error as expected
|
||||
|
||||
function f<T>(t: T) {
|
||||
var x: T | null = Math.random() > 0.5 ? null : t;
|
||||
onlyNullablePlease(x); // should work
|
||||
onlyNullablePlease2(x); // should work
|
||||
}
|
||||
|
||||
function f2<T>(t1: { x: T; y: T }, t2: T extends T ? { x: T; y: T } : never) {
|
||||
t1 = t2; // OK
|
||||
t2 = t1; // should fail
|
||||
}
|
||||
|
||||
type Foo<T> = T extends true ? string : "a";
|
||||
|
||||
function test<T>(x: Foo<T>, s: string) {
|
||||
x = "a"; // Currently an error, should be ok
|
||||
x = s; // Error
|
||||
}
|
||||
|
||||
// #26933
|
||||
type Distributive<T> = T extends { a: number } ? { a: number } : { b: number };
|
||||
function testAssignabilityToConditionalType<T>() {
|
||||
const o = { a: 1, b: 2 };
|
||||
const x: [T] extends [string]
|
||||
? { y: number }
|
||||
: { a: number; b: number } = undefined!;
|
||||
// Simple case: OK
|
||||
const o1: [T] extends [number] ? { a: number } : { b: number } = o;
|
||||
// Simple case where source happens to be a conditional type: also OK
|
||||
const x1: [T] extends [number]
|
||||
? ([T] extends [string] ? { y: number } : { a: number })
|
||||
: ([T] extends [string] ? { y: number } : { b: number }) = x;
|
||||
// Infer type parameters: no good
|
||||
const o2: [T] extends [[infer U]] ? U : { b: number } = o;
|
||||
|
||||
// The next 4 are arguable - if you choose to ignore the `never` distribution case,
|
||||
// then they're all good. The `never` case _is_ a bit of an outlier - we say distributive types
|
||||
// look approximately like the sum of their branches, but the `never` case bucks that.
|
||||
// There's an argument for the result of dumping `never` into a distributive conditional
|
||||
// being not `never`, but instead the intersection of the branches - a much more precise bound
|
||||
// on that "impossible" input.
|
||||
|
||||
// Distributive where T might instantiate to never: no good
|
||||
const o3: Distributive<T> = o;
|
||||
// Distributive where T & string might instantiate to never: also no good
|
||||
const o4: Distributive<T & string> = o;
|
||||
// Distributive where {a: T} cannot instantiate to never: OK
|
||||
const o5: Distributive<{ a: T }> = o;
|
||||
// Distributive where check type is a conditional which returns a non-never type upon instantiation with `never` but can still return never otherwise: no good
|
||||
const o6: Distributive<[T] extends [never] ? { a: number } : never> = o;
|
||||
}
|
||||
|
||||
type Wrapped<T> = { ___secret: T };
|
||||
type Unwrap<T> = T extends Wrapped<infer U> ? U : T;
|
||||
|
||||
declare function set<T, K extends keyof T>(
|
||||
obj: T,
|
||||
key: K,
|
||||
value: Unwrap<T[K]>
|
||||
): Unwrap<T[K]>;
|
||||
|
||||
class Foo2 {
|
||||
prop!: Wrapped<string>;
|
||||
|
||||
method() {
|
||||
set(this, "prop", "hi"); // <-- type error
|
||||
}
|
||||
}
|
||||
|
||||
set(new Foo2(), "prop", "hi"); // <-- typechecks
|
||||
|
||||
type InferBecauseWhyNot<T> = [T] extends [(p: infer P1) => any]
|
||||
? P1 | T
|
||||
: never;
|
||||
|
||||
function f3<Q extends (arg: any) => any>(x: Q): InferBecauseWhyNot<Q> {
|
||||
return x;
|
||||
}
|
||||
|
||||
type InferBecauseWhyNotDistributive<T> = T extends (p: infer P1) => any
|
||||
? P1 | T
|
||||
: never;
|
||||
|
||||
function f4<Q extends (arg: any) => any>(
|
||||
x: Q
|
||||
): InferBecauseWhyNotDistributive<Q> {
|
||||
return x; // should fail
|
||||
}
|
||||
|
||||
|
||||
//// [conditionalTypeAssignabilityWhenDeferred.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.func = void 0;
|
||||
function select(property, list, valueProp) { }
|
||||
function func(x, tipos) {
|
||||
select(x, tipos, "value");
|
||||
}
|
||||
exports.func = func;
|
||||
onlyNullablePlease(z); // works as expected
|
||||
onlyNullablePlease2(z); // works as expected
|
||||
onlyNullablePlease(y); // error as expected
|
||||
onlyNullablePlease2(y); // error as expected
|
||||
function f(t) {
|
||||
var x = Math.random() > 0.5 ? null : t;
|
||||
onlyNullablePlease(x); // should work
|
||||
onlyNullablePlease2(x); // should work
|
||||
}
|
||||
function f2(t1, t2) {
|
||||
t1 = t2; // OK
|
||||
t2 = t1; // should fail
|
||||
}
|
||||
function test(x, s) {
|
||||
x = "a"; // Currently an error, should be ok
|
||||
x = s; // Error
|
||||
}
|
||||
function testAssignabilityToConditionalType() {
|
||||
var o = { a: 1, b: 2 };
|
||||
var x = undefined;
|
||||
// Simple case: OK
|
||||
var o1 = o;
|
||||
// Simple case where source happens to be a conditional type: also OK
|
||||
var x1 = x;
|
||||
// Infer type parameters: no good
|
||||
var o2 = o;
|
||||
// The next 4 are arguable - if you choose to ignore the `never` distribution case,
|
||||
// then they're all good. The `never` case _is_ a bit of an outlier - we say distributive types
|
||||
// look approximately like the sum of their branches, but the `never` case bucks that.
|
||||
// There's an argument for the result of dumping `never` into a distributive conditional
|
||||
// being not `never`, but instead the intersection of the branches - a much more precise bound
|
||||
// on that "impossible" input.
|
||||
// Distributive where T might instantiate to never: no good
|
||||
var o3 = o;
|
||||
// Distributive where T & string might instantiate to never: also no good
|
||||
var o4 = o;
|
||||
// Distributive where {a: T} cannot instantiate to never: OK
|
||||
var o5 = o;
|
||||
// Distributive where check type is a conditional which returns a non-never type upon instantiation with `never` but can still return never otherwise: no good
|
||||
var o6 = o;
|
||||
}
|
||||
var Foo2 = /** @class */ (function () {
|
||||
function Foo2() {
|
||||
}
|
||||
Foo2.prototype.method = function () {
|
||||
set(this, "prop", "hi"); // <-- type error
|
||||
};
|
||||
return Foo2;
|
||||
}());
|
||||
set(new Foo2(), "prop", "hi"); // <-- typechecks
|
||||
function f3(x) {
|
||||
return x;
|
||||
}
|
||||
function f4(x) {
|
||||
return x; // should fail
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
=== tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts ===
|
||||
export type FilterPropsByType<T, TT> = {
|
||||
>FilterPropsByType : Symbol(FilterPropsByType, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 0, 30))
|
||||
>TT : Symbol(TT, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 0, 32))
|
||||
|
||||
[K in keyof T]: T[K] extends TT ? K : never
|
||||
>K : Symbol(K, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 1, 3))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 0, 30))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 0, 30))
|
||||
>K : Symbol(K, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 1, 3))
|
||||
>TT : Symbol(TT, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 0, 32))
|
||||
>K : Symbol(K, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 1, 3))
|
||||
|
||||
}[keyof T];
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 0, 30))
|
||||
|
||||
function select<
|
||||
>select : Symbol(select, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 2, 11))
|
||||
|
||||
T extends string | number,
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 4, 16))
|
||||
|
||||
TList extends object,
|
||||
>TList : Symbol(TList, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 5, 28))
|
||||
|
||||
TValueProp extends FilterPropsByType<TList, T>
|
||||
>TValueProp : Symbol(TValueProp, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 6, 23))
|
||||
>FilterPropsByType : Symbol(FilterPropsByType, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 0, 0))
|
||||
>TList : Symbol(TList, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 5, 28))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 4, 16))
|
||||
|
||||
>(property: T, list: TList[], valueProp: TValueProp) {}
|
||||
>property : Symbol(property, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 8, 2))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 4, 16))
|
||||
>list : Symbol(list, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 8, 14))
|
||||
>TList : Symbol(TList, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 5, 28))
|
||||
>valueProp : Symbol(valueProp, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 8, 29))
|
||||
>TValueProp : Symbol(TValueProp, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 6, 23))
|
||||
|
||||
export function func<XX extends string>(x: XX, tipos: { value: XX }[]) {
|
||||
>func : Symbol(func, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 8, 55))
|
||||
>XX : Symbol(XX, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 10, 21))
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 10, 40))
|
||||
>XX : Symbol(XX, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 10, 21))
|
||||
>tipos : Symbol(tipos, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 10, 46))
|
||||
>value : Symbol(value, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 10, 55))
|
||||
>XX : Symbol(XX, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 10, 21))
|
||||
|
||||
select(x, tipos, "value");
|
||||
>select : Symbol(select, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 2, 11))
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 10, 40))
|
||||
>tipos : Symbol(tipos, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 10, 46))
|
||||
}
|
||||
|
||||
declare function onlyNullablePlease<T extends null extends T ? any : never>(
|
||||
>onlyNullablePlease : Symbol(onlyNullablePlease, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 12, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 14, 36))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 14, 36))
|
||||
|
||||
value: T
|
||||
>value : Symbol(value, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 14, 76))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 14, 36))
|
||||
|
||||
): void;
|
||||
|
||||
declare function onlyNullablePlease2<
|
||||
>onlyNullablePlease2 : Symbol(onlyNullablePlease2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 16, 8))
|
||||
|
||||
T extends [null] extends [T] ? any : never
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 18, 37))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 18, 37))
|
||||
|
||||
>(value: T): void;
|
||||
>value : Symbol(value, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 20, 2))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 18, 37))
|
||||
|
||||
declare var z: string | null;
|
||||
>z : Symbol(z, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 22, 11))
|
||||
|
||||
onlyNullablePlease(z); // works as expected
|
||||
>onlyNullablePlease : Symbol(onlyNullablePlease, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 12, 1))
|
||||
>z : Symbol(z, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 22, 11))
|
||||
|
||||
onlyNullablePlease2(z); // works as expected
|
||||
>onlyNullablePlease2 : Symbol(onlyNullablePlease2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 16, 8))
|
||||
>z : Symbol(z, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 22, 11))
|
||||
|
||||
declare var y: string;
|
||||
>y : Symbol(y, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 26, 11))
|
||||
|
||||
onlyNullablePlease(y); // error as expected
|
||||
>onlyNullablePlease : Symbol(onlyNullablePlease, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 12, 1))
|
||||
>y : Symbol(y, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 26, 11))
|
||||
|
||||
onlyNullablePlease2(y); // error as expected
|
||||
>onlyNullablePlease2 : Symbol(onlyNullablePlease2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 16, 8))
|
||||
>y : Symbol(y, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 26, 11))
|
||||
|
||||
function f<T>(t: T) {
|
||||
>f : Symbol(f, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 28, 23))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 30, 11))
|
||||
>t : Symbol(t, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 30, 14))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 30, 11))
|
||||
|
||||
var x: T | null = Math.random() > 0.5 ? null : t;
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 31, 5))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 30, 11))
|
||||
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
|
||||
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
|
||||
>t : Symbol(t, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 30, 14))
|
||||
|
||||
onlyNullablePlease(x); // should work
|
||||
>onlyNullablePlease : Symbol(onlyNullablePlease, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 12, 1))
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 31, 5))
|
||||
|
||||
onlyNullablePlease2(x); // should work
|
||||
>onlyNullablePlease2 : Symbol(onlyNullablePlease2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 16, 8))
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 31, 5))
|
||||
}
|
||||
|
||||
function f2<T>(t1: { x: T; y: T }, t2: T extends T ? { x: T; y: T } : never) {
|
||||
>f2 : Symbol(f2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 34, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 12))
|
||||
>t1 : Symbol(t1, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 15))
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 20))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 12))
|
||||
>y : Symbol(y, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 26))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 12))
|
||||
>t2 : Symbol(t2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 34))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 12))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 12))
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 54))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 12))
|
||||
>y : Symbol(y, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 60))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 12))
|
||||
|
||||
t1 = t2; // OK
|
||||
>t1 : Symbol(t1, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 15))
|
||||
>t2 : Symbol(t2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 34))
|
||||
|
||||
t2 = t1; // should fail
|
||||
>t2 : Symbol(t2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 34))
|
||||
>t1 : Symbol(t1, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 36, 15))
|
||||
}
|
||||
|
||||
type Foo<T> = T extends true ? string : "a";
|
||||
>Foo : Symbol(Foo, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 39, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 41, 9))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 41, 9))
|
||||
|
||||
function test<T>(x: Foo<T>, s: string) {
|
||||
>test : Symbol(test, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 41, 44))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 43, 14))
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 43, 17))
|
||||
>Foo : Symbol(Foo, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 39, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 43, 14))
|
||||
>s : Symbol(s, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 43, 27))
|
||||
|
||||
x = "a"; // Currently an error, should be ok
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 43, 17))
|
||||
|
||||
x = s; // Error
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 43, 17))
|
||||
>s : Symbol(s, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 43, 27))
|
||||
}
|
||||
|
||||
// #26933
|
||||
type Distributive<T> = T extends { a: number } ? { a: number } : { b: number };
|
||||
>Distributive : Symbol(Distributive, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 46, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 49, 18))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 49, 18))
|
||||
>a : Symbol(a, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 49, 34))
|
||||
>a : Symbol(a, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 49, 50))
|
||||
>b : Symbol(b, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 49, 66))
|
||||
|
||||
function testAssignabilityToConditionalType<T>() {
|
||||
>testAssignabilityToConditionalType : Symbol(testAssignabilityToConditionalType, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 49, 79))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
|
||||
const o = { a: 1, b: 2 };
|
||||
>o : Symbol(o, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 51, 7))
|
||||
>a : Symbol(a, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 51, 13))
|
||||
>b : Symbol(b, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 51, 19))
|
||||
|
||||
const x: [T] extends [string]
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 52, 7))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
|
||||
? { y: number }
|
||||
>y : Symbol(y, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 53, 7))
|
||||
|
||||
: { a: number; b: number } = undefined!;
|
||||
>a : Symbol(a, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 54, 7))
|
||||
>b : Symbol(b, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 54, 18))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
// Simple case: OK
|
||||
const o1: [T] extends [number] ? { a: number } : { b: number } = o;
|
||||
>o1 : Symbol(o1, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 56, 7))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
>a : Symbol(a, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 56, 36))
|
||||
>b : Symbol(b, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 56, 52))
|
||||
>o : Symbol(o, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 51, 7))
|
||||
|
||||
// Simple case where source happens to be a conditional type: also OK
|
||||
const x1: [T] extends [number]
|
||||
>x1 : Symbol(x1, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 58, 7))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
|
||||
? ([T] extends [string] ? { y: number } : { a: number })
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
>y : Symbol(y, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 59, 31))
|
||||
>a : Symbol(a, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 59, 47))
|
||||
|
||||
: ([T] extends [string] ? { y: number } : { b: number }) = x;
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
>y : Symbol(y, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 60, 31))
|
||||
>b : Symbol(b, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 60, 47))
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 52, 7))
|
||||
|
||||
// Infer type parameters: no good
|
||||
const o2: [T] extends [[infer U]] ? U : { b: number } = o;
|
||||
>o2 : Symbol(o2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 62, 7))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
>U : Symbol(U, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 62, 31))
|
||||
>U : Symbol(U, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 62, 31))
|
||||
>b : Symbol(b, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 62, 43))
|
||||
>o : Symbol(o, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 51, 7))
|
||||
|
||||
// The next 4 are arguable - if you choose to ignore the `never` distribution case,
|
||||
// then they're all good. The `never` case _is_ a bit of an outlier - we say distributive types
|
||||
// look approximately like the sum of their branches, but the `never` case bucks that.
|
||||
// There's an argument for the result of dumping `never` into a distributive conditional
|
||||
// being not `never`, but instead the intersection of the branches - a much more precise bound
|
||||
// on that "impossible" input.
|
||||
|
||||
// Distributive where T might instantiate to never: no good
|
||||
const o3: Distributive<T> = o;
|
||||
>o3 : Symbol(o3, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 72, 7))
|
||||
>Distributive : Symbol(Distributive, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 46, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
>o : Symbol(o, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 51, 7))
|
||||
|
||||
// Distributive where T & string might instantiate to never: also no good
|
||||
const o4: Distributive<T & string> = o;
|
||||
>o4 : Symbol(o4, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 74, 7))
|
||||
>Distributive : Symbol(Distributive, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 46, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
>o : Symbol(o, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 51, 7))
|
||||
|
||||
// Distributive where {a: T} cannot instantiate to never: OK
|
||||
const o5: Distributive<{ a: T }> = o;
|
||||
>o5 : Symbol(o5, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 76, 7))
|
||||
>Distributive : Symbol(Distributive, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 46, 1))
|
||||
>a : Symbol(a, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 76, 26))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
>o : Symbol(o, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 51, 7))
|
||||
|
||||
// Distributive where check type is a conditional which returns a non-never type upon instantiation with `never` but can still return never otherwise: no good
|
||||
const o6: Distributive<[T] extends [never] ? { a: number } : never> = o;
|
||||
>o6 : Symbol(o6, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 78, 7))
|
||||
>Distributive : Symbol(Distributive, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 46, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 50, 44))
|
||||
>a : Symbol(a, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 78, 48))
|
||||
>o : Symbol(o, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 51, 7))
|
||||
}
|
||||
|
||||
type Wrapped<T> = { ___secret: T };
|
||||
>Wrapped : Symbol(Wrapped, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 79, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 81, 13))
|
||||
>___secret : Symbol(___secret, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 81, 19))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 81, 13))
|
||||
|
||||
type Unwrap<T> = T extends Wrapped<infer U> ? U : T;
|
||||
>Unwrap : Symbol(Unwrap, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 81, 35))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 82, 12))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 82, 12))
|
||||
>Wrapped : Symbol(Wrapped, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 79, 1))
|
||||
>U : Symbol(U, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 82, 40))
|
||||
>U : Symbol(U, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 82, 40))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 82, 12))
|
||||
|
||||
declare function set<T, K extends keyof T>(
|
||||
>set : Symbol(set, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 82, 52))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 21))
|
||||
>K : Symbol(K, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 23))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 21))
|
||||
|
||||
obj: T,
|
||||
>obj : Symbol(obj, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 43))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 21))
|
||||
|
||||
key: K,
|
||||
>key : Symbol(key, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 85, 9))
|
||||
>K : Symbol(K, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 23))
|
||||
|
||||
value: Unwrap<T[K]>
|
||||
>value : Symbol(value, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 86, 9))
|
||||
>Unwrap : Symbol(Unwrap, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 81, 35))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 21))
|
||||
>K : Symbol(K, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 23))
|
||||
|
||||
): Unwrap<T[K]>;
|
||||
>Unwrap : Symbol(Unwrap, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 81, 35))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 21))
|
||||
>K : Symbol(K, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 84, 23))
|
||||
|
||||
class Foo2 {
|
||||
>Foo2 : Symbol(Foo2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 88, 16))
|
||||
|
||||
prop!: Wrapped<string>;
|
||||
>prop : Symbol(Foo2.prop, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 90, 12))
|
||||
>Wrapped : Symbol(Wrapped, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 79, 1))
|
||||
|
||||
method() {
|
||||
>method : Symbol(Foo2.method, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 91, 25))
|
||||
|
||||
set(this, "prop", "hi"); // <-- type error
|
||||
>set : Symbol(set, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 82, 52))
|
||||
>this : Symbol(Foo2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 88, 16))
|
||||
}
|
||||
}
|
||||
|
||||
set(new Foo2(), "prop", "hi"); // <-- typechecks
|
||||
>set : Symbol(set, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 82, 52))
|
||||
>Foo2 : Symbol(Foo2, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 88, 16))
|
||||
|
||||
type InferBecauseWhyNot<T> = [T] extends [(p: infer P1) => any]
|
||||
>InferBecauseWhyNot : Symbol(InferBecauseWhyNot, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 98, 30))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 100, 24))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 100, 24))
|
||||
>p : Symbol(p, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 100, 43))
|
||||
>P1 : Symbol(P1, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 100, 51))
|
||||
|
||||
? P1 | T
|
||||
>P1 : Symbol(P1, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 100, 51))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 100, 24))
|
||||
|
||||
: never;
|
||||
|
||||
function f3<Q extends (arg: any) => any>(x: Q): InferBecauseWhyNot<Q> {
|
||||
>f3 : Symbol(f3, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 102, 10))
|
||||
>Q : Symbol(Q, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 104, 12))
|
||||
>arg : Symbol(arg, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 104, 23))
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 104, 41))
|
||||
>Q : Symbol(Q, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 104, 12))
|
||||
>InferBecauseWhyNot : Symbol(InferBecauseWhyNot, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 98, 30))
|
||||
>Q : Symbol(Q, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 104, 12))
|
||||
|
||||
return x;
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 104, 41))
|
||||
}
|
||||
|
||||
type InferBecauseWhyNotDistributive<T> = T extends (p: infer P1) => any
|
||||
>InferBecauseWhyNotDistributive : Symbol(InferBecauseWhyNotDistributive, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 106, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 108, 36))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 108, 36))
|
||||
>p : Symbol(p, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 108, 52))
|
||||
>P1 : Symbol(P1, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 108, 60))
|
||||
|
||||
? P1 | T
|
||||
>P1 : Symbol(P1, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 108, 60))
|
||||
>T : Symbol(T, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 108, 36))
|
||||
|
||||
: never;
|
||||
|
||||
function f4<Q extends (arg: any) => any>(
|
||||
>f4 : Symbol(f4, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 110, 10))
|
||||
>Q : Symbol(Q, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 112, 12))
|
||||
>arg : Symbol(arg, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 112, 23))
|
||||
|
||||
x: Q
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 112, 41))
|
||||
>Q : Symbol(Q, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 112, 12))
|
||||
|
||||
): InferBecauseWhyNotDistributive<Q> {
|
||||
>InferBecauseWhyNotDistributive : Symbol(InferBecauseWhyNotDistributive, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 106, 1))
|
||||
>Q : Symbol(Q, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 112, 12))
|
||||
|
||||
return x; // should fail
|
||||
>x : Symbol(x, Decl(conditionalTypeAssignabilityWhenDeferred.ts, 112, 41))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,313 @@
|
||||
=== tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts ===
|
||||
export type FilterPropsByType<T, TT> = {
|
||||
>FilterPropsByType : FilterPropsByType<T, TT>
|
||||
|
||||
[K in keyof T]: T[K] extends TT ? K : never
|
||||
}[keyof T];
|
||||
|
||||
function select<
|
||||
>select : <T extends string | number, TList extends object, TValueProp extends FilterPropsByType<TList, T>>(property: T, list: TList[], valueProp: TValueProp) => void
|
||||
|
||||
T extends string | number,
|
||||
TList extends object,
|
||||
TValueProp extends FilterPropsByType<TList, T>
|
||||
>(property: T, list: TList[], valueProp: TValueProp) {}
|
||||
>property : T
|
||||
>list : TList[]
|
||||
>valueProp : TValueProp
|
||||
|
||||
export function func<XX extends string>(x: XX, tipos: { value: XX }[]) {
|
||||
>func : <XX extends string>(x: XX, tipos: { value: XX;}[]) => void
|
||||
>x : XX
|
||||
>tipos : { value: XX; }[]
|
||||
>value : XX
|
||||
|
||||
select(x, tipos, "value");
|
||||
>select(x, tipos, "value") : void
|
||||
>select : <T extends string | number, TList extends object, TValueProp extends FilterPropsByType<TList, T>>(property: T, list: TList[], valueProp: TValueProp) => void
|
||||
>x : XX
|
||||
>tipos : { value: XX; }[]
|
||||
>"value" : "value"
|
||||
}
|
||||
|
||||
declare function onlyNullablePlease<T extends null extends T ? any : never>(
|
||||
>onlyNullablePlease : <T extends null extends T ? any : never>(value: T) => void
|
||||
>null : null
|
||||
|
||||
value: T
|
||||
>value : T
|
||||
|
||||
): void;
|
||||
|
||||
declare function onlyNullablePlease2<
|
||||
>onlyNullablePlease2 : <T extends [null] extends [T] ? any : never>(value: T) => void
|
||||
|
||||
T extends [null] extends [T] ? any : never
|
||||
>null : null
|
||||
|
||||
>(value: T): void;
|
||||
>value : T
|
||||
|
||||
declare var z: string | null;
|
||||
>z : string | null
|
||||
>null : null
|
||||
|
||||
onlyNullablePlease(z); // works as expected
|
||||
>onlyNullablePlease(z) : void
|
||||
>onlyNullablePlease : <T extends null extends T ? any : never>(value: T) => void
|
||||
>z : string | null
|
||||
|
||||
onlyNullablePlease2(z); // works as expected
|
||||
>onlyNullablePlease2(z) : void
|
||||
>onlyNullablePlease2 : <T extends [null] extends [T] ? any : never>(value: T) => void
|
||||
>z : string | null
|
||||
|
||||
declare var y: string;
|
||||
>y : string
|
||||
|
||||
onlyNullablePlease(y); // error as expected
|
||||
>onlyNullablePlease(y) : void
|
||||
>onlyNullablePlease : <T extends null extends T ? any : never>(value: T) => void
|
||||
>y : string
|
||||
|
||||
onlyNullablePlease2(y); // error as expected
|
||||
>onlyNullablePlease2(y) : void
|
||||
>onlyNullablePlease2 : <T extends [null] extends [T] ? any : never>(value: T) => void
|
||||
>y : string
|
||||
|
||||
function f<T>(t: T) {
|
||||
>f : <T>(t: T) => void
|
||||
>t : T
|
||||
|
||||
var x: T | null = Math.random() > 0.5 ? null : t;
|
||||
>x : T | null
|
||||
>null : null
|
||||
>Math.random() > 0.5 ? null : t : T | null
|
||||
>Math.random() > 0.5 : boolean
|
||||
>Math.random() : number
|
||||
>Math.random : () => number
|
||||
>Math : Math
|
||||
>random : () => number
|
||||
>0.5 : 0.5
|
||||
>null : null
|
||||
>t : T
|
||||
|
||||
onlyNullablePlease(x); // should work
|
||||
>onlyNullablePlease(x) : void
|
||||
>onlyNullablePlease : <T extends null extends T ? any : never>(value: T) => void
|
||||
>x : T | null
|
||||
|
||||
onlyNullablePlease2(x); // should work
|
||||
>onlyNullablePlease2(x) : void
|
||||
>onlyNullablePlease2 : <T extends [null] extends [T] ? any : never>(value: T) => void
|
||||
>x : T | null
|
||||
}
|
||||
|
||||
function f2<T>(t1: { x: T; y: T }, t2: T extends T ? { x: T; y: T } : never) {
|
||||
>f2 : <T>(t1: { x: T; y: T;}, t2: T extends T ? { x: T; y: T;} : never) => void
|
||||
>t1 : { x: T; y: T; }
|
||||
>x : T
|
||||
>y : T
|
||||
>t2 : T extends T ? { x: T; y: T; } : never
|
||||
>x : T
|
||||
>y : T
|
||||
|
||||
t1 = t2; // OK
|
||||
>t1 = t2 : T extends T ? { x: T; y: T; } : never
|
||||
>t1 : { x: T; y: T; }
|
||||
>t2 : T extends T ? { x: T; y: T; } : never
|
||||
|
||||
t2 = t1; // should fail
|
||||
>t2 = t1 : { x: T; y: T; }
|
||||
>t2 : T extends T ? { x: T; y: T; } : never
|
||||
>t1 : { x: T; y: T; }
|
||||
}
|
||||
|
||||
type Foo<T> = T extends true ? string : "a";
|
||||
>Foo : Foo<T>
|
||||
>true : true
|
||||
|
||||
function test<T>(x: Foo<T>, s: string) {
|
||||
>test : <T>(x: Foo<T>, s: string) => void
|
||||
>x : Foo<T>
|
||||
>s : string
|
||||
|
||||
x = "a"; // Currently an error, should be ok
|
||||
>x = "a" : "a"
|
||||
>x : Foo<T>
|
||||
>"a" : "a"
|
||||
|
||||
x = s; // Error
|
||||
>x = s : string
|
||||
>x : Foo<T>
|
||||
>s : string
|
||||
}
|
||||
|
||||
// #26933
|
||||
type Distributive<T> = T extends { a: number } ? { a: number } : { b: number };
|
||||
>Distributive : Distributive<T>
|
||||
>a : number
|
||||
>a : number
|
||||
>b : number
|
||||
|
||||
function testAssignabilityToConditionalType<T>() {
|
||||
>testAssignabilityToConditionalType : <T>() => void
|
||||
|
||||
const o = { a: 1, b: 2 };
|
||||
>o : { a: number; b: number; }
|
||||
>{ a: 1, b: 2 } : { a: number; b: number; }
|
||||
>a : number
|
||||
>1 : 1
|
||||
>b : number
|
||||
>2 : 2
|
||||
|
||||
const x: [T] extends [string]
|
||||
>x : [T] extends [string] ? { y: number; } : { a: number; b: number; }
|
||||
|
||||
? { y: number }
|
||||
>y : number
|
||||
|
||||
: { a: number; b: number } = undefined!;
|
||||
>a : number
|
||||
>b : number
|
||||
>undefined! : never
|
||||
>undefined : undefined
|
||||
|
||||
// Simple case: OK
|
||||
const o1: [T] extends [number] ? { a: number } : { b: number } = o;
|
||||
>o1 : [T] extends [number] ? { a: number; } : { b: number; }
|
||||
>a : number
|
||||
>b : number
|
||||
>o : { a: number; b: number; }
|
||||
|
||||
// Simple case where source happens to be a conditional type: also OK
|
||||
const x1: [T] extends [number]
|
||||
>x1 : [T] extends [number] ? [T] extends [string] ? { y: number; } : { a: number; } : [T] extends [string] ? { y: number; } : { b: number; }
|
||||
|
||||
? ([T] extends [string] ? { y: number } : { a: number })
|
||||
>y : number
|
||||
>a : number
|
||||
|
||||
: ([T] extends [string] ? { y: number } : { b: number }) = x;
|
||||
>y : number
|
||||
>b : number
|
||||
>x : [T] extends [string] ? { y: number; } : { a: number; b: number; }
|
||||
|
||||
// Infer type parameters: no good
|
||||
const o2: [T] extends [[infer U]] ? U : { b: number } = o;
|
||||
>o2 : [T] extends [[infer U]] ? U : { b: number; }
|
||||
>b : number
|
||||
>o : { a: number; b: number; }
|
||||
|
||||
// The next 4 are arguable - if you choose to ignore the `never` distribution case,
|
||||
// then they're all good. The `never` case _is_ a bit of an outlier - we say distributive types
|
||||
// look approximately like the sum of their branches, but the `never` case bucks that.
|
||||
// There's an argument for the result of dumping `never` into a distributive conditional
|
||||
// being not `never`, but instead the intersection of the branches - a much more precise bound
|
||||
// on that "impossible" input.
|
||||
|
||||
// Distributive where T might instantiate to never: no good
|
||||
const o3: Distributive<T> = o;
|
||||
>o3 : Distributive<T>
|
||||
>o : { a: number; b: number; }
|
||||
|
||||
// Distributive where T & string might instantiate to never: also no good
|
||||
const o4: Distributive<T & string> = o;
|
||||
>o4 : Distributive<T & string>
|
||||
>o : { a: number; b: number; }
|
||||
|
||||
// Distributive where {a: T} cannot instantiate to never: OK
|
||||
const o5: Distributive<{ a: T }> = o;
|
||||
>o5 : Distributive<{ a: T; }>
|
||||
>a : T
|
||||
>o : { a: number; b: number; }
|
||||
|
||||
// Distributive where check type is a conditional which returns a non-never type upon instantiation with `never` but can still return never otherwise: no good
|
||||
const o6: Distributive<[T] extends [never] ? { a: number } : never> = o;
|
||||
>o6 : Distributive<[T] extends [never] ? { a: number; } : never>
|
||||
>a : number
|
||||
>o : { a: number; b: number; }
|
||||
}
|
||||
|
||||
type Wrapped<T> = { ___secret: T };
|
||||
>Wrapped : Wrapped<T>
|
||||
>___secret : T
|
||||
|
||||
type Unwrap<T> = T extends Wrapped<infer U> ? U : T;
|
||||
>Unwrap : Unwrap<T>
|
||||
|
||||
declare function set<T, K extends keyof T>(
|
||||
>set : <T, K extends keyof T>(obj: T, key: K, value: Unwrap<T[K]>) => Unwrap<T[K]>
|
||||
|
||||
obj: T,
|
||||
>obj : T
|
||||
|
||||
key: K,
|
||||
>key : K
|
||||
|
||||
value: Unwrap<T[K]>
|
||||
>value : Unwrap<T[K]>
|
||||
|
||||
): Unwrap<T[K]>;
|
||||
|
||||
class Foo2 {
|
||||
>Foo2 : Foo2
|
||||
|
||||
prop!: Wrapped<string>;
|
||||
>prop : Wrapped<string>
|
||||
|
||||
method() {
|
||||
>method : () => void
|
||||
|
||||
set(this, "prop", "hi"); // <-- type error
|
||||
>set(this, "prop", "hi") : Unwrap<this["prop"]>
|
||||
>set : <T, K extends keyof T>(obj: T, key: K, value: Unwrap<T[K]>) => Unwrap<T[K]>
|
||||
>this : this
|
||||
>"prop" : "prop"
|
||||
>"hi" : "hi"
|
||||
}
|
||||
}
|
||||
|
||||
set(new Foo2(), "prop", "hi"); // <-- typechecks
|
||||
>set(new Foo2(), "prop", "hi") : string
|
||||
>set : <T, K extends keyof T>(obj: T, key: K, value: Unwrap<T[K]>) => Unwrap<T[K]>
|
||||
>new Foo2() : Foo2
|
||||
>Foo2 : typeof Foo2
|
||||
>"prop" : "prop"
|
||||
>"hi" : "hi"
|
||||
|
||||
type InferBecauseWhyNot<T> = [T] extends [(p: infer P1) => any]
|
||||
>InferBecauseWhyNot : InferBecauseWhyNot<T>
|
||||
>p : P1
|
||||
|
||||
? P1 | T
|
||||
: never;
|
||||
|
||||
function f3<Q extends (arg: any) => any>(x: Q): InferBecauseWhyNot<Q> {
|
||||
>f3 : <Q extends (arg: any) => any>(x: Q) => InferBecauseWhyNot<Q>
|
||||
>arg : any
|
||||
>x : Q
|
||||
|
||||
return x;
|
||||
>x : Q
|
||||
}
|
||||
|
||||
type InferBecauseWhyNotDistributive<T> = T extends (p: infer P1) => any
|
||||
>InferBecauseWhyNotDistributive : InferBecauseWhyNotDistributive<T>
|
||||
>p : P1
|
||||
|
||||
? P1 | T
|
||||
: never;
|
||||
|
||||
function f4<Q extends (arg: any) => any>(
|
||||
>f4 : <Q extends (arg: any) => any>(x: Q) => InferBecauseWhyNotDistributive<Q>
|
||||
>arg : any
|
||||
|
||||
x: Q
|
||||
>x : Q
|
||||
|
||||
): InferBecauseWhyNotDistributive<Q> {
|
||||
return x; // should fail
|
||||
>x : Q
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//// [conditionalTypeSubclassExtendsTypeParam.ts]
|
||||
declare class Model<M extends MR, MR extends {}> {
|
||||
public getField2<K extends keyof M>(): Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
|
||||
}
|
||||
|
||||
declare class Field<T extends TR, TR> {
|
||||
}
|
||||
|
||||
//// [conditionalTypeSubclassExtendsTypeParam.js]
|
||||
@@ -0,0 +1,28 @@
|
||||
=== tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts ===
|
||||
declare class Model<M extends MR, MR extends {}> {
|
||||
>Model : Symbol(Model, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 0))
|
||||
>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20))
|
||||
>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33))
|
||||
>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33))
|
||||
|
||||
public getField2<K extends keyof M>(): Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
|
||||
>getField2 : Symbol(Model.getField2, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 50))
|
||||
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
|
||||
>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20))
|
||||
>Field : Symbol(Field, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 2, 1))
|
||||
>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20))
|
||||
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
|
||||
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
|
||||
>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33))
|
||||
>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33))
|
||||
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
|
||||
>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20))
|
||||
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
|
||||
}
|
||||
|
||||
declare class Field<T extends TR, TR> {
|
||||
>Field : Symbol(Field, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 2, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 4, 20))
|
||||
>TR : Symbol(TR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 4, 33))
|
||||
>TR : Symbol(TR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 4, 33))
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts ===
|
||||
declare class Model<M extends MR, MR extends {}> {
|
||||
>Model : Model<M, MR>
|
||||
|
||||
public getField2<K extends keyof M>(): Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
|
||||
>getField2 : <K extends keyof M>() => Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
|
||||
}
|
||||
|
||||
declare class Field<T extends TR, TR> {
|
||||
>Field : Field<T, TR>
|
||||
}
|
||||
572
tests/baselines/reference/ramdaToolsNoInfinite2.js
Normal file
572
tests/baselines/reference/ramdaToolsNoInfinite2.js
Normal file
@@ -0,0 +1,572 @@
|
||||
//// [ramdaToolsNoInfinite2.ts]
|
||||
declare module "Any/Kind" {
|
||||
import { Extends } from "Any/Extends";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Kind<A extends any> = Extends<A, Function> extends 1 ? 'function' : Extends<A, List> extends 1 ? 'array' : Extends<A, object> extends 1 ? 'object' : Extends<A, string> extends 1 ? 'string' : Extends<A, number> extends 1 ? 'number' : Extends<A, boolean> extends 1 ? 'boolean' : 'unknown';
|
||||
}
|
||||
declare module "Any/Compute" {
|
||||
export type Compute<A extends any> = A extends Function ? A : {
|
||||
[K in keyof A]: A[K];
|
||||
} & {};
|
||||
}
|
||||
declare module "Object/Pick" {
|
||||
import { Key } from "Any/Key";
|
||||
|
||||
type __Pick<O extends object, K extends keyof O> = {
|
||||
[P in K]: O[P];
|
||||
} & {};
|
||||
|
||||
export type _Pick<O extends object, K extends Key> = __Pick<O, keyof O & K>;
|
||||
|
||||
export type Pick<O extends object, K extends Key> = O extends unknown ? _Pick<O, K & keyof O> : never;
|
||||
}
|
||||
declare module "Object/Keys" {
|
||||
import { Keys as UKeys } from "Union/Keys";
|
||||
|
||||
export type Keys<O extends object> = UKeys<O>;
|
||||
}
|
||||
declare module "Object/Omit" {
|
||||
import { _Pick } from "Object/Pick";
|
||||
import { Exclude } from "Union/Exclude";
|
||||
import { Key } from "Any/Key";
|
||||
import { Keys } from "Object/Keys";
|
||||
export type _Omit<O extends object, K extends Key> = _Pick<O, Exclude<Keys<O>, K>>;
|
||||
|
||||
export type Omit<O extends object, K extends Key> = O extends unknown ? _Omit<O, K> : never;
|
||||
}
|
||||
declare module "Object/At" {
|
||||
import { Key } from "Any/Key";
|
||||
import { Boolean } from "Boolean/Boolean";
|
||||
|
||||
type AtStrict<O extends object, K extends Key> = [K & keyof O] extends [never] ? never : O[K & keyof O];
|
||||
|
||||
type AtLoose<O extends object, K extends Key> = O extends unknown ? AtStrict<O, K> : never;
|
||||
|
||||
export type At<O extends object, K extends Key, strict extends Boolean = 1> = {
|
||||
1: AtStrict<O, K>;
|
||||
0: AtLoose<O, K>;
|
||||
}[strict];
|
||||
}
|
||||
declare module "Boolean/Boolean" {
|
||||
export type Boolean = True | False;
|
||||
|
||||
export type True = 1;
|
||||
|
||||
export type False = 0;
|
||||
}
|
||||
declare module "Boolean/Not" {
|
||||
import { Boolean } from "Boolean/Boolean";
|
||||
|
||||
export type Not<B extends Boolean> = {
|
||||
0: 1;
|
||||
1: 0;
|
||||
}[B];
|
||||
}
|
||||
declare module "Union/Has" {
|
||||
import { Union } from "Union/Union";
|
||||
import { Not } from "Boolean/Not";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
export type Has<U extends Union, U1 extends Union> = Not<Extends<Exclude<U1, U>, U1>>;
|
||||
}
|
||||
declare module "Union/Union" {
|
||||
export type Union = any;
|
||||
}
|
||||
declare module "Union/Exclude" {
|
||||
import { Union } from "Union/Union";
|
||||
|
||||
export type Exclude<U extends Union, M extends Union> = U extends M ? never : U;
|
||||
}
|
||||
declare module "Any/_Internal" {
|
||||
import { _NumberOf } from "Number/NumberOf";
|
||||
|
||||
export type Match = 'default' | 'implements->' | '<-implements' | 'extends->' | '<-extends' | 'equals';
|
||||
|
||||
export type NumberOf<N extends any> = N extends number ? _NumberOf<N> : N;
|
||||
}
|
||||
declare module "Any/Implements" {
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
export type Implements<A1 extends any, A2 extends any> = Extends<A1, A2> extends 1 ? 1 : 0;
|
||||
}
|
||||
declare module "Any/Key" {
|
||||
export type Key = string | number | symbol;
|
||||
}
|
||||
declare module "Union/Keys" {
|
||||
import { Union } from "Union/Union";
|
||||
import { Key } from "Any/Key";
|
||||
|
||||
export type Keys<U extends Union> = (U extends unknown ? keyof U : never) & Key;
|
||||
}
|
||||
declare module "List/ObjectOf" {
|
||||
import { _Omit } from "Object/Omit";
|
||||
import { Has } from "Union/Has";
|
||||
import { At } from "Object/At";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type _ObjectOf<L extends object> = Has<keyof L, keyof List> extends 1 ? number extends At<L, 'length'> ? _Omit<L, Exclude<keyof any[], number>> : _Omit<L, keyof any[]> : L;
|
||||
|
||||
export type ObjectOf<L extends object> = L extends unknown ? _ObjectOf<L> : never;
|
||||
}
|
||||
declare module "List/Keys" {
|
||||
import { Exclude } from "Union/Exclude";
|
||||
import { List } from "List/List";
|
||||
import { Keys as UKeys } from "Union/Keys";
|
||||
|
||||
export type Keys<L extends List> = Exclude<UKeys<L>, keyof any[]> | number;
|
||||
}
|
||||
declare module "Object/Merge" {
|
||||
import { _Omit } from "Object/Omit";
|
||||
import { At } from "Object/At";
|
||||
import { Compute } from "Any/Compute";
|
||||
import { Depth } from "Object/_Internal";
|
||||
import { Kind } from "Any/Kind";
|
||||
|
||||
export type MergeFlat<O extends object, O1 extends object> = Compute<O & _Omit<O1, keyof O>>;
|
||||
|
||||
export type MergeDeep<O, O1> = (Kind<(O | O1)> extends 'object' ? MergeFlat<O & {}, O1 & {}> extends infer M ? {
|
||||
[K in keyof M]: MergeDeep<M[K], At<O1 & {}, K>>;
|
||||
} & {} : never : O);
|
||||
|
||||
export type Merge<O extends object, O1 extends object, depth extends Depth = 'flat'> = {
|
||||
'flat': MergeFlat<O, O1>;
|
||||
'deep': MergeDeep<O, O1>;
|
||||
}[depth];
|
||||
}
|
||||
declare module "Union/NonNullable" {
|
||||
import { Exclude } from "Union/Exclude";
|
||||
import { Union } from "Union/Union";
|
||||
|
||||
export type NonNullable<U extends Union> = Exclude<U, undefined | null>;
|
||||
}
|
||||
declare module "Object/ListOf" {
|
||||
import { IterationOf } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { Key } from "Iteration/Key";
|
||||
import { Next } from "Iteration/Next";
|
||||
import { _Append } from "List/Append";
|
||||
import { Exclude } from "Union/Exclude";
|
||||
import { List } from "List/List";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
type PickIfEntry<O extends object, LN extends List, I extends Iteration> = Key<I> extends keyof O ? _Append<LN, O[Cast<Key<I>, keyof O>]> : LN;
|
||||
|
||||
type __ListOf<O extends object, K, LN extends List = [], I extends Iteration = IterationOf<'0'>> = {
|
||||
0: __ListOf<O, Exclude<K, Key<I>>, PickIfEntry<O, LN, I>, Next<I>>;
|
||||
1: LN;
|
||||
}[Extends<[K], [never]>];
|
||||
|
||||
export type _ListOf<O extends object> = __ListOf<O, keyof O> extends infer X ? Cast<X, List> : never;
|
||||
|
||||
export type ListOf<O extends object> = O extends unknown ? _ListOf<O> : never;
|
||||
}
|
||||
declare module "Object/NonNullable" {
|
||||
import { MergeFlat } from "Object/Merge";
|
||||
import { NonNullable as UNonNullable } from "Union/NonNullable";
|
||||
import { Depth } from "Object/_Internal";
|
||||
import { Pick } from "Object/Pick";
|
||||
import { Key } from "Any/Key";
|
||||
import { Implements } from "Any/Implements";
|
||||
import { Keys } from "Object/Keys";
|
||||
|
||||
export type NonNullableFlat<O> = {
|
||||
[K in keyof O]: UNonNullable<O[K]>;
|
||||
} & {};
|
||||
|
||||
export type NonNullableDeep<O> = {
|
||||
[K in keyof O]: NonNullableDeep<UNonNullable<O[K]>>;
|
||||
};
|
||||
|
||||
type NonNullablePart<O extends object, depth extends Depth> = {
|
||||
'flat': NonNullableFlat<O>;
|
||||
'deep': NonNullableDeep<O>;
|
||||
}[depth];
|
||||
|
||||
export type NonNullable<O extends object, K extends Key = Key, depth extends Depth = 'flat'> = {
|
||||
1: NonNullablePart<O, depth>;
|
||||
0: MergeFlat<NonNullablePart<Pick<O, K>, depth>, O>;
|
||||
}[Implements<Keys<O>, K>] & {};
|
||||
}
|
||||
declare module "Object/Overwrite" {
|
||||
export type Overwrite<O extends object, O1 extends object> = {
|
||||
[K in keyof O]: K extends keyof O1 ? O1[K] : O[K];
|
||||
} & {};
|
||||
}
|
||||
declare module "Number/_Internal" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
import { Format } from "Iteration/Format";
|
||||
|
||||
export type Formats = 'b' | 'n' | 's';
|
||||
|
||||
type KnownIterationMapKeys = '-40' | '-39' | '-38' | '-37' | '-36' | '-35' | '-34' | '-33' | '-32' | '-31' | '-30' | '-29' | '-28' | '-27' | '-26' | '-25' | '-24' | '-23' | '-22' | '-21' | '-20' | '-19' | '-18' | '-17' | '-16' | '-15' | '-14' | '-13' | '-12' | '-11' | '-10' | '-9' | '-8' | '-7' | '-6' | '-5' | '-4' | '-3' | '-2' | '-1' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '30' | '31' | '32' | '33' | '34' | '35' | '36' | '37' | '38' | '39' | '40';
|
||||
|
||||
type PositiveIterationKeys = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '30' | '31' | '32' | '33' | '34' | '35' | '36' | '37' | '38' | '39' | '40';
|
||||
|
||||
type NegativeIterationKeys = '-40' | '-39' | '-38' | '-37' | '-36' | '-35' | '-34' | '-33' | '-32' | '-31' | '-30' | '-29' | '-28' | '-27' | '-26' | '-25' | '-24' | '-23' | '-22' | '-21' | '-20' | '-19' | '-18' | '-17' | '-16' | '-15' | '-14' | '-13' | '-12' | '-11' | '-10' | '-9' | '-8' | '-7' | '-6' | '-5' | '-4' | '-3' | '-2' | '-1';
|
||||
|
||||
export type Numbers = {
|
||||
'string': {
|
||||
'all': Format<IterationMap[KnownIterationMapKeys], 's'>;
|
||||
'+': Format<IterationMap[PositiveIterationKeys], 's'>;
|
||||
'-': Format<IterationMap[NegativeIterationKeys], 's'>;
|
||||
'0': Format<IterationMap['0'], 's'>;
|
||||
};
|
||||
'number': {
|
||||
'all': Format<IterationMap[KnownIterationMapKeys], 'n'>;
|
||||
'+': Format<IterationMap[PositiveIterationKeys], 'n'>;
|
||||
'-': Format<IterationMap[NegativeIterationKeys], 'n'>;
|
||||
'0': Format<IterationMap['0'], 'n'>;
|
||||
};
|
||||
};
|
||||
}
|
||||
declare module "Number/Number" {
|
||||
export type Number = string;
|
||||
}
|
||||
declare module "Iteration/_Internal" {
|
||||
export type Formats = 'n' | 's';
|
||||
export type Way = '->' | '<-';
|
||||
}
|
||||
declare module "List/Prepend" {
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Prepend<L extends List, A extends any> = ((head: A, ...args: L) => any) extends ((...args: infer U) => any) ? U : L;
|
||||
}
|
||||
declare module "List/_Internal" {
|
||||
import { Overwrite } from "Object/Overwrite";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Naked<L extends List> = Overwrite<Required<L>, L>;
|
||||
}
|
||||
declare module "List/Tail" {
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Tail<L extends List> = ((...t: L) => any) extends ((head: any, ...tail: infer LTail) => any) ? LTail : never;
|
||||
}
|
||||
declare module "Iteration/Format" {
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Formats } from "Iteration/_Internal";
|
||||
|
||||
export type Format<I extends Iteration, fmt extends Formats> = {
|
||||
's': I[2];
|
||||
'n': I[3];
|
||||
}[fmt];
|
||||
}
|
||||
declare module "Iteration/Pos" {
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Format } from "Iteration/Format";
|
||||
|
||||
export type Pos<I extends Iteration> = Format<I, 'n'>;
|
||||
}
|
||||
declare module "List/Append" {
|
||||
import { _Concat } from "List/Concat";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type _Append<L extends List, A extends any> = _Concat<L, [A]>;
|
||||
|
||||
export type Append<L extends List, A extends any> = L extends unknown ? A extends unknown ? _Append<L, A> : never : never;
|
||||
}
|
||||
declare module "List/Reverse" {
|
||||
import { Prepend } from "List/Prepend";
|
||||
import { Pos } from "Iteration/Pos";
|
||||
import { Next } from "Iteration/Next";
|
||||
import { Length } from "List/Length";
|
||||
import { IterationOf } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { List } from "List/List";
|
||||
import { Naked } from "List/_Internal";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
type __Reverse<L extends List, LO extends List, I extends Iteration = IterationOf<'0'>> = {
|
||||
0: __Reverse<L, Prepend<LO, L[Pos<I>]>, Next<I>>;
|
||||
1: LO;
|
||||
}[Extends<Pos<I>, Length<L>>];
|
||||
|
||||
export type _Reverse<L extends List, LO extends List = []> = __Reverse<Naked<L>, LO> extends infer X ? Cast<X, List> : never;
|
||||
|
||||
export type Reverse<L extends List, LO extends List = []> = L extends unknown ? LO extends unknown ? _Reverse<L, LO> : never : never;
|
||||
}
|
||||
declare module "List/Concat" {
|
||||
import { _Reverse } from "List/Reverse";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type _Concat<L extends List, L1 extends List> = _Reverse<_Reverse<L>, L1>;
|
||||
|
||||
export type Concat<L extends List, L1 extends List> = L extends unknown ? L1 extends L1 ? _Concat<L, L1> : never : never;
|
||||
}
|
||||
declare module "List/Drop" {
|
||||
import { Tail } from "List/Tail";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { IterationOf } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Number } from "Number/Number";
|
||||
import { Way } from "Iteration/_Internal";
|
||||
import { List } from "List/List";
|
||||
import { Pos } from "Iteration/Pos";
|
||||
import { Prev } from "Iteration/Prev";
|
||||
import { Prepend } from "List/Prepend";
|
||||
import { Naked } from "List/_Internal";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
type DropForth<L extends List, N extends Iteration> = {
|
||||
0: DropForth<Tail<L>, Prev<N>>;
|
||||
1: L;
|
||||
}[Extends<0, Pos<N>>];
|
||||
|
||||
type DropBack<L extends List, N extends Iteration, I extends Iteration = Prev<N>, LN extends List = []> = {
|
||||
0: DropBack<L, N, Prev<I>, Prepend<LN, L[Pos<I>]>>;
|
||||
1: LN;
|
||||
}[Extends<-1, Pos<I>>];
|
||||
|
||||
type __Drop<L extends List, N extends Iteration, way extends Way = '->'> = {
|
||||
'->': DropForth<L, N>;
|
||||
'<-': DropBack<L, N>;
|
||||
}[way];
|
||||
|
||||
export type _Drop<L extends List, N extends Number, way extends Way = '->'> = __Drop<Naked<L>, IterationOf<N>, way> extends infer X ? Cast<X, List> : never;
|
||||
|
||||
export type Drop<L extends List, N extends Number, way extends Way = '->'> = L extends unknown ? N extends unknown ? _Drop<L, N, way> : never : never;
|
||||
}
|
||||
declare module "List/Length" {
|
||||
import { NumberOf } from "Number/NumberOf";
|
||||
import { Formats } from "Iteration/_Internal";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Length<L extends List, fmt extends Formats = 'n'> = {
|
||||
's': NumberOf<L['length']>;
|
||||
'n': L['length'];
|
||||
}[fmt];
|
||||
}
|
||||
declare module "Iteration/Next" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
|
||||
export type Next<I extends Iteration> = IterationMap[I[1]];
|
||||
}
|
||||
declare module "Any/Cast" {
|
||||
export type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
|
||||
}
|
||||
declare module "Function/Parameters" {
|
||||
import { Function } from "Function/Function";
|
||||
|
||||
export type Parameters<F extends Function> = F extends ((...args: infer L) => any) ? L : never;
|
||||
}
|
||||
declare module "Function/Return" {
|
||||
import { Function } from "Function/Function";
|
||||
|
||||
export type Return<F extends Function> = F extends ((...args: any[]) => infer R) ? R : never;
|
||||
}
|
||||
declare module "Iteration/Prev" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
|
||||
export type Prev<I extends Iteration> = IterationMap[I[0]];
|
||||
}
|
||||
declare module "Number/NumberOf" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
import { Key } from "Iteration/Key";
|
||||
import { Pos } from "Iteration/Pos";
|
||||
import { Numbers } from "Number/_Internal";
|
||||
|
||||
export type _NumberOf<N extends number> = {
|
||||
[K in keyof IterationMap]: Pos<IterationMap[K]> extends N ? Key<IterationMap[K]> : never;
|
||||
}[keyof IterationMap];
|
||||
|
||||
export type NumberOf<N extends number> = N extends Numbers['number']['all'] ? _NumberOf<N> : string;
|
||||
}
|
||||
declare module "Object/_Internal" {
|
||||
export type Modx = ['?' | '!', 'W' | 'R'];
|
||||
|
||||
export type Depth = 'flat' | 'deep';
|
||||
|
||||
export type Empty<O extends object> = {
|
||||
[K in keyof O]: undefined;
|
||||
};
|
||||
}
|
||||
declare module "Iteration/IterationOf" {
|
||||
import { Number } from "Number/Number";
|
||||
|
||||
export type IterationMap = {
|
||||
'-40': ['__', '-39', '-40', -40, '-'];
|
||||
'-39': ['-40', '-38', '-39', -39, '-'];
|
||||
'-38': ['-39', '-37', '-38', -38, '-'];
|
||||
'-37': ['-38', '-36', '-37', -37, '-'];
|
||||
'-36': ['-37', '-35', '-36', -36, '-'];
|
||||
'-35': ['-36', '-34', '-35', -35, '-'];
|
||||
'-34': ['-35', '-33', '-34', -34, '-'];
|
||||
'-33': ['-34', '-32', '-33', -33, '-'];
|
||||
'-32': ['-33', '-31', '-32', -32, '-'];
|
||||
'-31': ['-32', '-30', '-31', -31, '-'];
|
||||
'-30': ['-31', '-29', '-30', -30, '-'];
|
||||
'-29': ['-30', '-28', '-29', -29, '-'];
|
||||
'-28': ['-29', '-27', '-28', -28, '-'];
|
||||
'-27': ['-28', '-26', '-27', -27, '-'];
|
||||
'-26': ['-27', '-25', '-26', -26, '-'];
|
||||
'-25': ['-26', '-24', '-25', -25, '-'];
|
||||
'-24': ['-25', '-23', '-24', -24, '-'];
|
||||
'-23': ['-24', '-22', '-23', -23, '-'];
|
||||
'-22': ['-23', '-21', '-22', -22, '-'];
|
||||
'-21': ['-22', '-20', '-21', -21, '-'];
|
||||
'-20': ['-21', '-19', '-20', -20, '-'];
|
||||
'-19': ['-20', '-18', '-19', -19, '-'];
|
||||
'-18': ['-19', '-17', '-18', -18, '-'];
|
||||
'-17': ['-18', '-16', '-17', -17, '-'];
|
||||
'-16': ['-17', '-15', '-16', -16, '-'];
|
||||
'-15': ['-16', '-14', '-15', -15, '-'];
|
||||
'-14': ['-15', '-13', '-14', -14, '-'];
|
||||
'-13': ['-14', '-12', '-13', -13, '-'];
|
||||
'-12': ['-13', '-11', '-12', -12, '-'];
|
||||
'-11': ['-12', '-10', '-11', -11, '-'];
|
||||
'-10': ['-11', '-9', '-10', -10, '-'];
|
||||
'-9': ['-10', '-8', '-9', -9, '-'];
|
||||
'-8': ['-9', '-7', '-8', -8, '-'];
|
||||
'-7': ['-8', '-6', '-7', -7, '-'];
|
||||
'-6': ['-7', '-5', '-6', -6, '-'];
|
||||
'-5': ['-6', '-4', '-5', -5, '-'];
|
||||
'-4': ['-5', '-3', '-4', -4, '-'];
|
||||
'-3': ['-4', '-2', '-3', -3, '-'];
|
||||
'-2': ['-3', '-1', '-2', -2, '-'];
|
||||
'-1': ['-2', '0', '-1', -1, '-'];
|
||||
'0': ['-1', '1', '0', 0, '0'];
|
||||
'1': ['0', '2', '1', 1, '+'];
|
||||
'2': ['1', '3', '2', 2, '+'];
|
||||
'3': ['2', '4', '3', 3, '+'];
|
||||
'4': ['3', '5', '4', 4, '+'];
|
||||
'5': ['4', '6', '5', 5, '+'];
|
||||
'6': ['5', '7', '6', 6, '+'];
|
||||
'7': ['6', '8', '7', 7, '+'];
|
||||
'8': ['7', '9', '8', 8, '+'];
|
||||
'9': ['8', '10', '9', 9, '+'];
|
||||
'10': ['9', '11', '10', 10, '+'];
|
||||
'11': ['10', '12', '11', 11, '+'];
|
||||
'12': ['11', '13', '12', 12, '+'];
|
||||
'13': ['12', '14', '13', 13, '+'];
|
||||
'14': ['13', '15', '14', 14, '+'];
|
||||
'15': ['14', '16', '15', 15, '+'];
|
||||
'16': ['15', '17', '16', 16, '+'];
|
||||
'17': ['16', '18', '17', 17, '+'];
|
||||
'18': ['17', '19', '18', 18, '+'];
|
||||
'19': ['18', '20', '19', 19, '+'];
|
||||
'20': ['19', '21', '20', 20, '+'];
|
||||
'21': ['20', '22', '21', 21, '+'];
|
||||
'22': ['21', '23', '22', 22, '+'];
|
||||
'23': ['22', '24', '23', 23, '+'];
|
||||
'24': ['23', '25', '24', 24, '+'];
|
||||
'25': ['24', '26', '25', 25, '+'];
|
||||
'26': ['25', '27', '26', 26, '+'];
|
||||
'27': ['26', '28', '27', 27, '+'];
|
||||
'28': ['27', '29', '28', 28, '+'];
|
||||
'29': ['28', '30', '29', 29, '+'];
|
||||
'30': ['29', '31', '30', 30, '+'];
|
||||
'31': ['30', '32', '31', 31, '+'];
|
||||
'32': ['31', '33', '32', 32, '+'];
|
||||
'33': ['32', '34', '33', 33, '+'];
|
||||
'34': ['33', '35', '34', 34, '+'];
|
||||
'35': ['34', '36', '35', 35, '+'];
|
||||
'36': ['35', '37', '36', 36, '+'];
|
||||
'37': ['36', '38', '37', 37, '+'];
|
||||
'38': ['37', '39', '38', 38, '+'];
|
||||
'39': ['38', '40', '39', 39, '+'];
|
||||
'40': ['39', '__', '40', 40, '+'];
|
||||
'__': ['__', '__', string, number, '-' | '0' | '+'];
|
||||
};
|
||||
|
||||
export type IterationOf<N extends Number> = N extends keyof IterationMap ? IterationMap[N] : IterationMap['__'];
|
||||
}
|
||||
declare module "Iteration/Iteration" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
|
||||
export type Iteration = [keyof IterationMap, keyof IterationMap, string, number, '-' | '0' | '+'];
|
||||
}
|
||||
declare module "Iteration/Key" {
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Format } from "Iteration/Format";
|
||||
|
||||
export type Key<I extends Iteration> = Format<I, 's'>;
|
||||
}
|
||||
declare module "List/NonNullable" {
|
||||
import { Depth } from "Object/_Internal";
|
||||
import { NonNullable as ONonNullable } from "Object/NonNullable";
|
||||
import { ListOf } from "Object/ListOf";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { Key } from "Any/Key";
|
||||
import { ObjectOf } from "List/ObjectOf";
|
||||
import { Implements } from "Any/Implements";
|
||||
import { Keys } from "List/Keys";
|
||||
import { List } from "List/List";
|
||||
import { NumberOf } from "Any/_Internal";
|
||||
|
||||
export type NonNullable<L extends List, K extends Key = Key, depth extends Depth = 'flat'> = {
|
||||
1: Cast<ONonNullable<L, Key, depth>, List>;
|
||||
0: ListOf<ONonNullable<ObjectOf<L>, NumberOf<K>, depth>>;
|
||||
}[Implements<Keys<L>, K>] & {};
|
||||
}
|
||||
declare module "Any/Type" {
|
||||
const symbol: unique symbol;
|
||||
|
||||
export type Type<A extends any, Id extends string> = A & {
|
||||
[K in typeof symbol]: Id;
|
||||
};
|
||||
}
|
||||
declare module "Any/x" {
|
||||
import { Type } from "Any/Type";
|
||||
|
||||
export type x = Type<{}, 'x'>;
|
||||
}
|
||||
declare module "List/List" {
|
||||
|
||||
export type List<A = any> = ReadonlyArray<A>;
|
||||
}
|
||||
declare module "Function/Function" {
|
||||
import { List } from "List/List";
|
||||
|
||||
export interface Function<P extends List = any, R extends any = any> {
|
||||
(...args: P): R;
|
||||
}
|
||||
}
|
||||
declare module "Any/Extends" {
|
||||
export type Extends<A1 extends any, A2 extends any> = [A1] extends [never] ? 0 : A1 extends A2 ? 1 : 0;
|
||||
}
|
||||
|
||||
declare module "Function/Curry" {
|
||||
import { Pos } from "Iteration/Pos";
|
||||
import { _Append } from "List/Append";
|
||||
import { _Concat } from "List/Concat";
|
||||
import { _Drop } from "List/Drop";
|
||||
import { Length } from "List/Length";
|
||||
import { Next } from "Iteration/Next";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { Parameters } from "Function/Parameters";
|
||||
import { Return } from "Function/Return";
|
||||
import { IterationOf } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Key } from "Iteration/Key";
|
||||
import { NonNullable } from "List/NonNullable";
|
||||
import { x } from "Any/x";
|
||||
import { List } from "List/List";
|
||||
import { Function } from "Function/Function";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
type GapOf<L1 extends List, L2 extends List, LN extends List, I extends Iteration = IterationOf<'0'>> = L1[Pos<I>] extends x ? _Append<LN, L2[Pos<I>]> : LN;
|
||||
|
||||
type _GapsOf<L1 extends List, L2 extends List, LN extends List = [], I extends Iteration = IterationOf<'0'>> = {
|
||||
0: _GapsOf<L1, L2, GapOf<L1, L2, LN, I>, Next<I>>;
|
||||
1: _Concat<LN, _Drop<L2, Key<I>>>;
|
||||
}[Extends<Pos<I>, Length<L1>>];
|
||||
|
||||
type GapsOf<L1 extends List, L2 extends List> = _GapsOf<L1, L2> extends infer X ? Cast<X, List> : never;
|
||||
|
||||
type Gaps<L extends List> = NonNullable<{
|
||||
[K in keyof L]?: L[K] | x;
|
||||
}>;
|
||||
|
||||
export type Curry<F extends Function> = <L extends List>(...args: Cast<L, Gaps<Parameters<F>>>) => GapsOf<L, Parameters<F>> extends infer G ? Length<Cast<G, List>> extends infer L ? L extends 0 ? Return<F> : L extends 1 ? Curry<(...args: Cast<G, List>) => Return<F>> & ((...args: Cast<G, List>) => Return<F>) : Curry<(...args: Cast<G, List>) => Return<F>> : never : never;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//// [ramdaToolsNoInfinite2.js]
|
||||
"use strict";
|
||||
1992
tests/baselines/reference/ramdaToolsNoInfinite2.symbols
Normal file
1992
tests/baselines/reference/ramdaToolsNoInfinite2.symbols
Normal file
File diff suppressed because it is too large
Load Diff
1354
tests/baselines/reference/ramdaToolsNoInfinite2.types
Normal file
1354
tests/baselines/reference/ramdaToolsNoInfinite2.types
Normal file
File diff suppressed because it is too large
Load Diff
118
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts
Normal file
118
tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts
Normal file
@@ -0,0 +1,118 @@
|
||||
// @strict: true
|
||||
export type FilterPropsByType<T, TT> = {
|
||||
[K in keyof T]: T[K] extends TT ? K : never
|
||||
}[keyof T];
|
||||
|
||||
function select<
|
||||
T extends string | number,
|
||||
TList extends object,
|
||||
TValueProp extends FilterPropsByType<TList, T>
|
||||
>(property: T, list: TList[], valueProp: TValueProp) {}
|
||||
|
||||
export function func<XX extends string>(x: XX, tipos: { value: XX }[]) {
|
||||
select(x, tipos, "value");
|
||||
}
|
||||
|
||||
declare function onlyNullablePlease<T extends null extends T ? any : never>(
|
||||
value: T
|
||||
): void;
|
||||
|
||||
declare function onlyNullablePlease2<
|
||||
T extends [null] extends [T] ? any : never
|
||||
>(value: T): void;
|
||||
|
||||
declare var z: string | null;
|
||||
onlyNullablePlease(z); // works as expected
|
||||
onlyNullablePlease2(z); // works as expected
|
||||
|
||||
declare var y: string;
|
||||
onlyNullablePlease(y); // error as expected
|
||||
onlyNullablePlease2(y); // error as expected
|
||||
|
||||
function f<T>(t: T) {
|
||||
var x: T | null = Math.random() > 0.5 ? null : t;
|
||||
onlyNullablePlease(x); // should work
|
||||
onlyNullablePlease2(x); // should work
|
||||
}
|
||||
|
||||
function f2<T>(t1: { x: T; y: T }, t2: T extends T ? { x: T; y: T } : never) {
|
||||
t1 = t2; // OK
|
||||
t2 = t1; // should fail
|
||||
}
|
||||
|
||||
type Foo<T> = T extends true ? string : "a";
|
||||
|
||||
function test<T>(x: Foo<T>, s: string) {
|
||||
x = "a"; // Currently an error, should be ok
|
||||
x = s; // Error
|
||||
}
|
||||
|
||||
// #26933
|
||||
type Distributive<T> = T extends { a: number } ? { a: number } : { b: number };
|
||||
function testAssignabilityToConditionalType<T>() {
|
||||
const o = { a: 1, b: 2 };
|
||||
const x: [T] extends [string]
|
||||
? { y: number }
|
||||
: { a: number; b: number } = undefined!;
|
||||
// Simple case: OK
|
||||
const o1: [T] extends [number] ? { a: number } : { b: number } = o;
|
||||
// Simple case where source happens to be a conditional type: also OK
|
||||
const x1: [T] extends [number]
|
||||
? ([T] extends [string] ? { y: number } : { a: number })
|
||||
: ([T] extends [string] ? { y: number } : { b: number }) = x;
|
||||
// Infer type parameters: no good
|
||||
const o2: [T] extends [[infer U]] ? U : { b: number } = o;
|
||||
|
||||
// The next 4 are arguable - if you choose to ignore the `never` distribution case,
|
||||
// then they're all good. The `never` case _is_ a bit of an outlier - we say distributive types
|
||||
// look approximately like the sum of their branches, but the `never` case bucks that.
|
||||
// There's an argument for the result of dumping `never` into a distributive conditional
|
||||
// being not `never`, but instead the intersection of the branches - a much more precise bound
|
||||
// on that "impossible" input.
|
||||
|
||||
// Distributive where T might instantiate to never: no good
|
||||
const o3: Distributive<T> = o;
|
||||
// Distributive where T & string might instantiate to never: also no good
|
||||
const o4: Distributive<T & string> = o;
|
||||
// Distributive where {a: T} cannot instantiate to never: OK
|
||||
const o5: Distributive<{ a: T }> = o;
|
||||
// Distributive where check type is a conditional which returns a non-never type upon instantiation with `never` but can still return never otherwise: no good
|
||||
const o6: Distributive<[T] extends [never] ? { a: number } : never> = o;
|
||||
}
|
||||
|
||||
type Wrapped<T> = { ___secret: T };
|
||||
type Unwrap<T> = T extends Wrapped<infer U> ? U : T;
|
||||
|
||||
declare function set<T, K extends keyof T>(
|
||||
obj: T,
|
||||
key: K,
|
||||
value: Unwrap<T[K]>
|
||||
): Unwrap<T[K]>;
|
||||
|
||||
class Foo2 {
|
||||
prop!: Wrapped<string>;
|
||||
|
||||
method() {
|
||||
set(this, "prop", "hi"); // <-- type error
|
||||
}
|
||||
}
|
||||
|
||||
set(new Foo2(), "prop", "hi"); // <-- typechecks
|
||||
|
||||
type InferBecauseWhyNot<T> = [T] extends [(p: infer P1) => any]
|
||||
? P1 | T
|
||||
: never;
|
||||
|
||||
function f3<Q extends (arg: any) => any>(x: Q): InferBecauseWhyNot<Q> {
|
||||
return x;
|
||||
}
|
||||
|
||||
type InferBecauseWhyNotDistributive<T> = T extends (p: infer P1) => any
|
||||
? P1 | T
|
||||
: never;
|
||||
|
||||
function f4<Q extends (arg: any) => any>(
|
||||
x: Q
|
||||
): InferBecauseWhyNotDistributive<Q> {
|
||||
return x; // should fail
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
declare class Model<M extends MR, MR extends {}> {
|
||||
public getField2<K extends keyof M>(): Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
|
||||
}
|
||||
|
||||
declare class Field<T extends TR, TR> {
|
||||
}
|
||||
568
tests/cases/compiler/ramdaToolsNoInfinite2.ts
Normal file
568
tests/cases/compiler/ramdaToolsNoInfinite2.ts
Normal file
@@ -0,0 +1,568 @@
|
||||
// @strict: true
|
||||
declare module "Any/Kind" {
|
||||
import { Extends } from "Any/Extends";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Kind<A extends any> = Extends<A, Function> extends 1 ? 'function' : Extends<A, List> extends 1 ? 'array' : Extends<A, object> extends 1 ? 'object' : Extends<A, string> extends 1 ? 'string' : Extends<A, number> extends 1 ? 'number' : Extends<A, boolean> extends 1 ? 'boolean' : 'unknown';
|
||||
}
|
||||
declare module "Any/Compute" {
|
||||
export type Compute<A extends any> = A extends Function ? A : {
|
||||
[K in keyof A]: A[K];
|
||||
} & {};
|
||||
}
|
||||
declare module "Object/Pick" {
|
||||
import { Key } from "Any/Key";
|
||||
|
||||
type __Pick<O extends object, K extends keyof O> = {
|
||||
[P in K]: O[P];
|
||||
} & {};
|
||||
|
||||
export type _Pick<O extends object, K extends Key> = __Pick<O, keyof O & K>;
|
||||
|
||||
export type Pick<O extends object, K extends Key> = O extends unknown ? _Pick<O, K & keyof O> : never;
|
||||
}
|
||||
declare module "Object/Keys" {
|
||||
import { Keys as UKeys } from "Union/Keys";
|
||||
|
||||
export type Keys<O extends object> = UKeys<O>;
|
||||
}
|
||||
declare module "Object/Omit" {
|
||||
import { _Pick } from "Object/Pick";
|
||||
import { Exclude } from "Union/Exclude";
|
||||
import { Key } from "Any/Key";
|
||||
import { Keys } from "Object/Keys";
|
||||
export type _Omit<O extends object, K extends Key> = _Pick<O, Exclude<Keys<O>, K>>;
|
||||
|
||||
export type Omit<O extends object, K extends Key> = O extends unknown ? _Omit<O, K> : never;
|
||||
}
|
||||
declare module "Object/At" {
|
||||
import { Key } from "Any/Key";
|
||||
import { Boolean } from "Boolean/Boolean";
|
||||
|
||||
type AtStrict<O extends object, K extends Key> = [K & keyof O] extends [never] ? never : O[K & keyof O];
|
||||
|
||||
type AtLoose<O extends object, K extends Key> = O extends unknown ? AtStrict<O, K> : never;
|
||||
|
||||
export type At<O extends object, K extends Key, strict extends Boolean = 1> = {
|
||||
1: AtStrict<O, K>;
|
||||
0: AtLoose<O, K>;
|
||||
}[strict];
|
||||
}
|
||||
declare module "Boolean/Boolean" {
|
||||
export type Boolean = True | False;
|
||||
|
||||
export type True = 1;
|
||||
|
||||
export type False = 0;
|
||||
}
|
||||
declare module "Boolean/Not" {
|
||||
import { Boolean } from "Boolean/Boolean";
|
||||
|
||||
export type Not<B extends Boolean> = {
|
||||
0: 1;
|
||||
1: 0;
|
||||
}[B];
|
||||
}
|
||||
declare module "Union/Has" {
|
||||
import { Union } from "Union/Union";
|
||||
import { Not } from "Boolean/Not";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
export type Has<U extends Union, U1 extends Union> = Not<Extends<Exclude<U1, U>, U1>>;
|
||||
}
|
||||
declare module "Union/Union" {
|
||||
export type Union = any;
|
||||
}
|
||||
declare module "Union/Exclude" {
|
||||
import { Union } from "Union/Union";
|
||||
|
||||
export type Exclude<U extends Union, M extends Union> = U extends M ? never : U;
|
||||
}
|
||||
declare module "Any/_Internal" {
|
||||
import { _NumberOf } from "Number/NumberOf";
|
||||
|
||||
export type Match = 'default' | 'implements->' | '<-implements' | 'extends->' | '<-extends' | 'equals';
|
||||
|
||||
export type NumberOf<N extends any> = N extends number ? _NumberOf<N> : N;
|
||||
}
|
||||
declare module "Any/Implements" {
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
export type Implements<A1 extends any, A2 extends any> = Extends<A1, A2> extends 1 ? 1 : 0;
|
||||
}
|
||||
declare module "Any/Key" {
|
||||
export type Key = string | number | symbol;
|
||||
}
|
||||
declare module "Union/Keys" {
|
||||
import { Union } from "Union/Union";
|
||||
import { Key } from "Any/Key";
|
||||
|
||||
export type Keys<U extends Union> = (U extends unknown ? keyof U : never) & Key;
|
||||
}
|
||||
declare module "List/ObjectOf" {
|
||||
import { _Omit } from "Object/Omit";
|
||||
import { Has } from "Union/Has";
|
||||
import { At } from "Object/At";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type _ObjectOf<L extends object> = Has<keyof L, keyof List> extends 1 ? number extends At<L, 'length'> ? _Omit<L, Exclude<keyof any[], number>> : _Omit<L, keyof any[]> : L;
|
||||
|
||||
export type ObjectOf<L extends object> = L extends unknown ? _ObjectOf<L> : never;
|
||||
}
|
||||
declare module "List/Keys" {
|
||||
import { Exclude } from "Union/Exclude";
|
||||
import { List } from "List/List";
|
||||
import { Keys as UKeys } from "Union/Keys";
|
||||
|
||||
export type Keys<L extends List> = Exclude<UKeys<L>, keyof any[]> | number;
|
||||
}
|
||||
declare module "Object/Merge" {
|
||||
import { _Omit } from "Object/Omit";
|
||||
import { At } from "Object/At";
|
||||
import { Compute } from "Any/Compute";
|
||||
import { Depth } from "Object/_Internal";
|
||||
import { Kind } from "Any/Kind";
|
||||
|
||||
export type MergeFlat<O extends object, O1 extends object> = Compute<O & _Omit<O1, keyof O>>;
|
||||
|
||||
export type MergeDeep<O, O1> = (Kind<(O | O1)> extends 'object' ? MergeFlat<O & {}, O1 & {}> extends infer M ? {
|
||||
[K in keyof M]: MergeDeep<M[K], At<O1 & {}, K>>;
|
||||
} & {} : never : O);
|
||||
|
||||
export type Merge<O extends object, O1 extends object, depth extends Depth = 'flat'> = {
|
||||
'flat': MergeFlat<O, O1>;
|
||||
'deep': MergeDeep<O, O1>;
|
||||
}[depth];
|
||||
}
|
||||
declare module "Union/NonNullable" {
|
||||
import { Exclude } from "Union/Exclude";
|
||||
import { Union } from "Union/Union";
|
||||
|
||||
export type NonNullable<U extends Union> = Exclude<U, undefined | null>;
|
||||
}
|
||||
declare module "Object/ListOf" {
|
||||
import { IterationOf } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { Key } from "Iteration/Key";
|
||||
import { Next } from "Iteration/Next";
|
||||
import { _Append } from "List/Append";
|
||||
import { Exclude } from "Union/Exclude";
|
||||
import { List } from "List/List";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
type PickIfEntry<O extends object, LN extends List, I extends Iteration> = Key<I> extends keyof O ? _Append<LN, O[Cast<Key<I>, keyof O>]> : LN;
|
||||
|
||||
type __ListOf<O extends object, K, LN extends List = [], I extends Iteration = IterationOf<'0'>> = {
|
||||
0: __ListOf<O, Exclude<K, Key<I>>, PickIfEntry<O, LN, I>, Next<I>>;
|
||||
1: LN;
|
||||
}[Extends<[K], [never]>];
|
||||
|
||||
export type _ListOf<O extends object> = __ListOf<O, keyof O> extends infer X ? Cast<X, List> : never;
|
||||
|
||||
export type ListOf<O extends object> = O extends unknown ? _ListOf<O> : never;
|
||||
}
|
||||
declare module "Object/NonNullable" {
|
||||
import { MergeFlat } from "Object/Merge";
|
||||
import { NonNullable as UNonNullable } from "Union/NonNullable";
|
||||
import { Depth } from "Object/_Internal";
|
||||
import { Pick } from "Object/Pick";
|
||||
import { Key } from "Any/Key";
|
||||
import { Implements } from "Any/Implements";
|
||||
import { Keys } from "Object/Keys";
|
||||
|
||||
export type NonNullableFlat<O> = {
|
||||
[K in keyof O]: UNonNullable<O[K]>;
|
||||
} & {};
|
||||
|
||||
export type NonNullableDeep<O> = {
|
||||
[K in keyof O]: NonNullableDeep<UNonNullable<O[K]>>;
|
||||
};
|
||||
|
||||
type NonNullablePart<O extends object, depth extends Depth> = {
|
||||
'flat': NonNullableFlat<O>;
|
||||
'deep': NonNullableDeep<O>;
|
||||
}[depth];
|
||||
|
||||
export type NonNullable<O extends object, K extends Key = Key, depth extends Depth = 'flat'> = {
|
||||
1: NonNullablePart<O, depth>;
|
||||
0: MergeFlat<NonNullablePart<Pick<O, K>, depth>, O>;
|
||||
}[Implements<Keys<O>, K>] & {};
|
||||
}
|
||||
declare module "Object/Overwrite" {
|
||||
export type Overwrite<O extends object, O1 extends object> = {
|
||||
[K in keyof O]: K extends keyof O1 ? O1[K] : O[K];
|
||||
} & {};
|
||||
}
|
||||
declare module "Number/_Internal" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
import { Format } from "Iteration/Format";
|
||||
|
||||
export type Formats = 'b' | 'n' | 's';
|
||||
|
||||
type KnownIterationMapKeys = '-40' | '-39' | '-38' | '-37' | '-36' | '-35' | '-34' | '-33' | '-32' | '-31' | '-30' | '-29' | '-28' | '-27' | '-26' | '-25' | '-24' | '-23' | '-22' | '-21' | '-20' | '-19' | '-18' | '-17' | '-16' | '-15' | '-14' | '-13' | '-12' | '-11' | '-10' | '-9' | '-8' | '-7' | '-6' | '-5' | '-4' | '-3' | '-2' | '-1' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '30' | '31' | '32' | '33' | '34' | '35' | '36' | '37' | '38' | '39' | '40';
|
||||
|
||||
type PositiveIterationKeys = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '30' | '31' | '32' | '33' | '34' | '35' | '36' | '37' | '38' | '39' | '40';
|
||||
|
||||
type NegativeIterationKeys = '-40' | '-39' | '-38' | '-37' | '-36' | '-35' | '-34' | '-33' | '-32' | '-31' | '-30' | '-29' | '-28' | '-27' | '-26' | '-25' | '-24' | '-23' | '-22' | '-21' | '-20' | '-19' | '-18' | '-17' | '-16' | '-15' | '-14' | '-13' | '-12' | '-11' | '-10' | '-9' | '-8' | '-7' | '-6' | '-5' | '-4' | '-3' | '-2' | '-1';
|
||||
|
||||
export type Numbers = {
|
||||
'string': {
|
||||
'all': Format<IterationMap[KnownIterationMapKeys], 's'>;
|
||||
'+': Format<IterationMap[PositiveIterationKeys], 's'>;
|
||||
'-': Format<IterationMap[NegativeIterationKeys], 's'>;
|
||||
'0': Format<IterationMap['0'], 's'>;
|
||||
};
|
||||
'number': {
|
||||
'all': Format<IterationMap[KnownIterationMapKeys], 'n'>;
|
||||
'+': Format<IterationMap[PositiveIterationKeys], 'n'>;
|
||||
'-': Format<IterationMap[NegativeIterationKeys], 'n'>;
|
||||
'0': Format<IterationMap['0'], 'n'>;
|
||||
};
|
||||
};
|
||||
}
|
||||
declare module "Number/Number" {
|
||||
export type Number = string;
|
||||
}
|
||||
declare module "Iteration/_Internal" {
|
||||
export type Formats = 'n' | 's';
|
||||
export type Way = '->' | '<-';
|
||||
}
|
||||
declare module "List/Prepend" {
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Prepend<L extends List, A extends any> = ((head: A, ...args: L) => any) extends ((...args: infer U) => any) ? U : L;
|
||||
}
|
||||
declare module "List/_Internal" {
|
||||
import { Overwrite } from "Object/Overwrite";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Naked<L extends List> = Overwrite<Required<L>, L>;
|
||||
}
|
||||
declare module "List/Tail" {
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Tail<L extends List> = ((...t: L) => any) extends ((head: any, ...tail: infer LTail) => any) ? LTail : never;
|
||||
}
|
||||
declare module "Iteration/Format" {
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Formats } from "Iteration/_Internal";
|
||||
|
||||
export type Format<I extends Iteration, fmt extends Formats> = {
|
||||
's': I[2];
|
||||
'n': I[3];
|
||||
}[fmt];
|
||||
}
|
||||
declare module "Iteration/Pos" {
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Format } from "Iteration/Format";
|
||||
|
||||
export type Pos<I extends Iteration> = Format<I, 'n'>;
|
||||
}
|
||||
declare module "List/Append" {
|
||||
import { _Concat } from "List/Concat";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type _Append<L extends List, A extends any> = _Concat<L, [A]>;
|
||||
|
||||
export type Append<L extends List, A extends any> = L extends unknown ? A extends unknown ? _Append<L, A> : never : never;
|
||||
}
|
||||
declare module "List/Reverse" {
|
||||
import { Prepend } from "List/Prepend";
|
||||
import { Pos } from "Iteration/Pos";
|
||||
import { Next } from "Iteration/Next";
|
||||
import { Length } from "List/Length";
|
||||
import { IterationOf } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { List } from "List/List";
|
||||
import { Naked } from "List/_Internal";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
type __Reverse<L extends List, LO extends List, I extends Iteration = IterationOf<'0'>> = {
|
||||
0: __Reverse<L, Prepend<LO, L[Pos<I>]>, Next<I>>;
|
||||
1: LO;
|
||||
}[Extends<Pos<I>, Length<L>>];
|
||||
|
||||
export type _Reverse<L extends List, LO extends List = []> = __Reverse<Naked<L>, LO> extends infer X ? Cast<X, List> : never;
|
||||
|
||||
export type Reverse<L extends List, LO extends List = []> = L extends unknown ? LO extends unknown ? _Reverse<L, LO> : never : never;
|
||||
}
|
||||
declare module "List/Concat" {
|
||||
import { _Reverse } from "List/Reverse";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type _Concat<L extends List, L1 extends List> = _Reverse<_Reverse<L>, L1>;
|
||||
|
||||
export type Concat<L extends List, L1 extends List> = L extends unknown ? L1 extends L1 ? _Concat<L, L1> : never : never;
|
||||
}
|
||||
declare module "List/Drop" {
|
||||
import { Tail } from "List/Tail";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { IterationOf } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Number } from "Number/Number";
|
||||
import { Way } from "Iteration/_Internal";
|
||||
import { List } from "List/List";
|
||||
import { Pos } from "Iteration/Pos";
|
||||
import { Prev } from "Iteration/Prev";
|
||||
import { Prepend } from "List/Prepend";
|
||||
import { Naked } from "List/_Internal";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
type DropForth<L extends List, N extends Iteration> = {
|
||||
0: DropForth<Tail<L>, Prev<N>>;
|
||||
1: L;
|
||||
}[Extends<0, Pos<N>>];
|
||||
|
||||
type DropBack<L extends List, N extends Iteration, I extends Iteration = Prev<N>, LN extends List = []> = {
|
||||
0: DropBack<L, N, Prev<I>, Prepend<LN, L[Pos<I>]>>;
|
||||
1: LN;
|
||||
}[Extends<-1, Pos<I>>];
|
||||
|
||||
type __Drop<L extends List, N extends Iteration, way extends Way = '->'> = {
|
||||
'->': DropForth<L, N>;
|
||||
'<-': DropBack<L, N>;
|
||||
}[way];
|
||||
|
||||
export type _Drop<L extends List, N extends Number, way extends Way = '->'> = __Drop<Naked<L>, IterationOf<N>, way> extends infer X ? Cast<X, List> : never;
|
||||
|
||||
export type Drop<L extends List, N extends Number, way extends Way = '->'> = L extends unknown ? N extends unknown ? _Drop<L, N, way> : never : never;
|
||||
}
|
||||
declare module "List/Length" {
|
||||
import { NumberOf } from "Number/NumberOf";
|
||||
import { Formats } from "Iteration/_Internal";
|
||||
import { List } from "List/List";
|
||||
|
||||
export type Length<L extends List, fmt extends Formats = 'n'> = {
|
||||
's': NumberOf<L['length']>;
|
||||
'n': L['length'];
|
||||
}[fmt];
|
||||
}
|
||||
declare module "Iteration/Next" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
|
||||
export type Next<I extends Iteration> = IterationMap[I[1]];
|
||||
}
|
||||
declare module "Any/Cast" {
|
||||
export type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
|
||||
}
|
||||
declare module "Function/Parameters" {
|
||||
import { Function } from "Function/Function";
|
||||
|
||||
export type Parameters<F extends Function> = F extends ((...args: infer L) => any) ? L : never;
|
||||
}
|
||||
declare module "Function/Return" {
|
||||
import { Function } from "Function/Function";
|
||||
|
||||
export type Return<F extends Function> = F extends ((...args: any[]) => infer R) ? R : never;
|
||||
}
|
||||
declare module "Iteration/Prev" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
|
||||
export type Prev<I extends Iteration> = IterationMap[I[0]];
|
||||
}
|
||||
declare module "Number/NumberOf" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
import { Key } from "Iteration/Key";
|
||||
import { Pos } from "Iteration/Pos";
|
||||
import { Numbers } from "Number/_Internal";
|
||||
|
||||
export type _NumberOf<N extends number> = {
|
||||
[K in keyof IterationMap]: Pos<IterationMap[K]> extends N ? Key<IterationMap[K]> : never;
|
||||
}[keyof IterationMap];
|
||||
|
||||
export type NumberOf<N extends number> = N extends Numbers['number']['all'] ? _NumberOf<N> : string;
|
||||
}
|
||||
declare module "Object/_Internal" {
|
||||
export type Modx = ['?' | '!', 'W' | 'R'];
|
||||
|
||||
export type Depth = 'flat' | 'deep';
|
||||
|
||||
export type Empty<O extends object> = {
|
||||
[K in keyof O]: undefined;
|
||||
};
|
||||
}
|
||||
declare module "Iteration/IterationOf" {
|
||||
import { Number } from "Number/Number";
|
||||
|
||||
export type IterationMap = {
|
||||
'-40': ['__', '-39', '-40', -40, '-'];
|
||||
'-39': ['-40', '-38', '-39', -39, '-'];
|
||||
'-38': ['-39', '-37', '-38', -38, '-'];
|
||||
'-37': ['-38', '-36', '-37', -37, '-'];
|
||||
'-36': ['-37', '-35', '-36', -36, '-'];
|
||||
'-35': ['-36', '-34', '-35', -35, '-'];
|
||||
'-34': ['-35', '-33', '-34', -34, '-'];
|
||||
'-33': ['-34', '-32', '-33', -33, '-'];
|
||||
'-32': ['-33', '-31', '-32', -32, '-'];
|
||||
'-31': ['-32', '-30', '-31', -31, '-'];
|
||||
'-30': ['-31', '-29', '-30', -30, '-'];
|
||||
'-29': ['-30', '-28', '-29', -29, '-'];
|
||||
'-28': ['-29', '-27', '-28', -28, '-'];
|
||||
'-27': ['-28', '-26', '-27', -27, '-'];
|
||||
'-26': ['-27', '-25', '-26', -26, '-'];
|
||||
'-25': ['-26', '-24', '-25', -25, '-'];
|
||||
'-24': ['-25', '-23', '-24', -24, '-'];
|
||||
'-23': ['-24', '-22', '-23', -23, '-'];
|
||||
'-22': ['-23', '-21', '-22', -22, '-'];
|
||||
'-21': ['-22', '-20', '-21', -21, '-'];
|
||||
'-20': ['-21', '-19', '-20', -20, '-'];
|
||||
'-19': ['-20', '-18', '-19', -19, '-'];
|
||||
'-18': ['-19', '-17', '-18', -18, '-'];
|
||||
'-17': ['-18', '-16', '-17', -17, '-'];
|
||||
'-16': ['-17', '-15', '-16', -16, '-'];
|
||||
'-15': ['-16', '-14', '-15', -15, '-'];
|
||||
'-14': ['-15', '-13', '-14', -14, '-'];
|
||||
'-13': ['-14', '-12', '-13', -13, '-'];
|
||||
'-12': ['-13', '-11', '-12', -12, '-'];
|
||||
'-11': ['-12', '-10', '-11', -11, '-'];
|
||||
'-10': ['-11', '-9', '-10', -10, '-'];
|
||||
'-9': ['-10', '-8', '-9', -9, '-'];
|
||||
'-8': ['-9', '-7', '-8', -8, '-'];
|
||||
'-7': ['-8', '-6', '-7', -7, '-'];
|
||||
'-6': ['-7', '-5', '-6', -6, '-'];
|
||||
'-5': ['-6', '-4', '-5', -5, '-'];
|
||||
'-4': ['-5', '-3', '-4', -4, '-'];
|
||||
'-3': ['-4', '-2', '-3', -3, '-'];
|
||||
'-2': ['-3', '-1', '-2', -2, '-'];
|
||||
'-1': ['-2', '0', '-1', -1, '-'];
|
||||
'0': ['-1', '1', '0', 0, '0'];
|
||||
'1': ['0', '2', '1', 1, '+'];
|
||||
'2': ['1', '3', '2', 2, '+'];
|
||||
'3': ['2', '4', '3', 3, '+'];
|
||||
'4': ['3', '5', '4', 4, '+'];
|
||||
'5': ['4', '6', '5', 5, '+'];
|
||||
'6': ['5', '7', '6', 6, '+'];
|
||||
'7': ['6', '8', '7', 7, '+'];
|
||||
'8': ['7', '9', '8', 8, '+'];
|
||||
'9': ['8', '10', '9', 9, '+'];
|
||||
'10': ['9', '11', '10', 10, '+'];
|
||||
'11': ['10', '12', '11', 11, '+'];
|
||||
'12': ['11', '13', '12', 12, '+'];
|
||||
'13': ['12', '14', '13', 13, '+'];
|
||||
'14': ['13', '15', '14', 14, '+'];
|
||||
'15': ['14', '16', '15', 15, '+'];
|
||||
'16': ['15', '17', '16', 16, '+'];
|
||||
'17': ['16', '18', '17', 17, '+'];
|
||||
'18': ['17', '19', '18', 18, '+'];
|
||||
'19': ['18', '20', '19', 19, '+'];
|
||||
'20': ['19', '21', '20', 20, '+'];
|
||||
'21': ['20', '22', '21', 21, '+'];
|
||||
'22': ['21', '23', '22', 22, '+'];
|
||||
'23': ['22', '24', '23', 23, '+'];
|
||||
'24': ['23', '25', '24', 24, '+'];
|
||||
'25': ['24', '26', '25', 25, '+'];
|
||||
'26': ['25', '27', '26', 26, '+'];
|
||||
'27': ['26', '28', '27', 27, '+'];
|
||||
'28': ['27', '29', '28', 28, '+'];
|
||||
'29': ['28', '30', '29', 29, '+'];
|
||||
'30': ['29', '31', '30', 30, '+'];
|
||||
'31': ['30', '32', '31', 31, '+'];
|
||||
'32': ['31', '33', '32', 32, '+'];
|
||||
'33': ['32', '34', '33', 33, '+'];
|
||||
'34': ['33', '35', '34', 34, '+'];
|
||||
'35': ['34', '36', '35', 35, '+'];
|
||||
'36': ['35', '37', '36', 36, '+'];
|
||||
'37': ['36', '38', '37', 37, '+'];
|
||||
'38': ['37', '39', '38', 38, '+'];
|
||||
'39': ['38', '40', '39', 39, '+'];
|
||||
'40': ['39', '__', '40', 40, '+'];
|
||||
'__': ['__', '__', string, number, '-' | '0' | '+'];
|
||||
};
|
||||
|
||||
export type IterationOf<N extends Number> = N extends keyof IterationMap ? IterationMap[N] : IterationMap['__'];
|
||||
}
|
||||
declare module "Iteration/Iteration" {
|
||||
import { IterationMap } from "Iteration/IterationOf";
|
||||
|
||||
export type Iteration = [keyof IterationMap, keyof IterationMap, string, number, '-' | '0' | '+'];
|
||||
}
|
||||
declare module "Iteration/Key" {
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Format } from "Iteration/Format";
|
||||
|
||||
export type Key<I extends Iteration> = Format<I, 's'>;
|
||||
}
|
||||
declare module "List/NonNullable" {
|
||||
import { Depth } from "Object/_Internal";
|
||||
import { NonNullable as ONonNullable } from "Object/NonNullable";
|
||||
import { ListOf } from "Object/ListOf";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { Key } from "Any/Key";
|
||||
import { ObjectOf } from "List/ObjectOf";
|
||||
import { Implements } from "Any/Implements";
|
||||
import { Keys } from "List/Keys";
|
||||
import { List } from "List/List";
|
||||
import { NumberOf } from "Any/_Internal";
|
||||
|
||||
export type NonNullable<L extends List, K extends Key = Key, depth extends Depth = 'flat'> = {
|
||||
1: Cast<ONonNullable<L, Key, depth>, List>;
|
||||
0: ListOf<ONonNullable<ObjectOf<L>, NumberOf<K>, depth>>;
|
||||
}[Implements<Keys<L>, K>] & {};
|
||||
}
|
||||
declare module "Any/Type" {
|
||||
const symbol: unique symbol;
|
||||
|
||||
export type Type<A extends any, Id extends string> = A & {
|
||||
[K in typeof symbol]: Id;
|
||||
};
|
||||
}
|
||||
declare module "Any/x" {
|
||||
import { Type } from "Any/Type";
|
||||
|
||||
export type x = Type<{}, 'x'>;
|
||||
}
|
||||
declare module "List/List" {
|
||||
|
||||
export type List<A = any> = ReadonlyArray<A>;
|
||||
}
|
||||
declare module "Function/Function" {
|
||||
import { List } from "List/List";
|
||||
|
||||
export interface Function<P extends List = any, R extends any = any> {
|
||||
(...args: P): R;
|
||||
}
|
||||
}
|
||||
declare module "Any/Extends" {
|
||||
export type Extends<A1 extends any, A2 extends any> = [A1] extends [never] ? 0 : A1 extends A2 ? 1 : 0;
|
||||
}
|
||||
|
||||
declare module "Function/Curry" {
|
||||
import { Pos } from "Iteration/Pos";
|
||||
import { _Append } from "List/Append";
|
||||
import { _Concat } from "List/Concat";
|
||||
import { _Drop } from "List/Drop";
|
||||
import { Length } from "List/Length";
|
||||
import { Next } from "Iteration/Next";
|
||||
import { Cast } from "Any/Cast";
|
||||
import { Parameters } from "Function/Parameters";
|
||||
import { Return } from "Function/Return";
|
||||
import { IterationOf } from "Iteration/IterationOf";
|
||||
import { Iteration } from "Iteration/Iteration";
|
||||
import { Key } from "Iteration/Key";
|
||||
import { NonNullable } from "List/NonNullable";
|
||||
import { x } from "Any/x";
|
||||
import { List } from "List/List";
|
||||
import { Function } from "Function/Function";
|
||||
import { Extends } from "Any/Extends";
|
||||
|
||||
type GapOf<L1 extends List, L2 extends List, LN extends List, I extends Iteration = IterationOf<'0'>> = L1[Pos<I>] extends x ? _Append<LN, L2[Pos<I>]> : LN;
|
||||
|
||||
type _GapsOf<L1 extends List, L2 extends List, LN extends List = [], I extends Iteration = IterationOf<'0'>> = {
|
||||
0: _GapsOf<L1, L2, GapOf<L1, L2, LN, I>, Next<I>>;
|
||||
1: _Concat<LN, _Drop<L2, Key<I>>>;
|
||||
}[Extends<Pos<I>, Length<L1>>];
|
||||
|
||||
type GapsOf<L1 extends List, L2 extends List> = _GapsOf<L1, L2> extends infer X ? Cast<X, List> : never;
|
||||
|
||||
type Gaps<L extends List> = NonNullable<{
|
||||
[K in keyof L]?: L[K] | x;
|
||||
}>;
|
||||
|
||||
export type Curry<F extends Function> = <L extends List>(...args: Cast<L, Gaps<Parameters<F>>>) => GapsOf<L, Parameters<F>> extends infer G ? Length<Cast<G, List>> extends infer L ? L extends 0 ? Return<F> : L extends 1 ? Curry<(...args: Cast<G, List>) => Return<F>> & ((...args: Cast<G, List>) => Return<F>) : Curry<(...args: Cast<G, List>) => Return<F>> : never : never;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user