1/* 2* Copyright (c) Microsoft Corporation. All rights reserved. 3* Copyright (c) 2023 Huawei Device Co., Ltd. 4* Licensed under the Apache License, Version 2.0 (the "License"); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an "AS IS" BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15* 16* This file has been modified by Huawei to verify type inference by adding verification statements. 17*/ 18 19// === tests/cases/compiler/ramdaToolsNoInfinite2.ts === 20declare function AssertType(value:any, type:string):void; 21 22declare module "Any/Kind" { 23 import { Extends } from "Any/Extends"; 24 import { List } from "List/List"; 25 26 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'; 27} 28declare module "Any/Compute" { 29 export type Compute<A extends any> = A extends Function ? A : { 30 [K in keyof A]: A[K]; 31 } & {}; 32} 33declare module "Object/Pick" { 34 import { Key } from "Any/Key"; 35 36 type __Pick<O extends object, K extends keyof O> = { 37 [P in K]: O[P]; 38 } & {}; 39 40 export type _Pick<O extends object, K extends Key> = __Pick<O, keyof O & K>; 41 42 export type Pick<O extends object, K extends Key> = O extends unknown ? _Pick<O, K & keyof O> : never; 43} 44declare module "Object/Keys" { 45 import { Keys as UKeys } from "Union/Keys"; 46 47 export type Keys<O extends object> = UKeys<O>; 48} 49declare module "Object/Omit" { 50 import { _Pick } from "Object/Pick"; 51 import { Exclude } from "Union/Exclude"; 52 import { Key } from "Any/Key"; 53 import { Keys } from "Object/Keys"; 54 export type _Omit<O extends object, K extends Key> = _Pick<O, Exclude<Keys<O>, K>>; 55 56 export type Omit<O extends object, K extends Key> = O extends unknown ? _Omit<O, K> : never; 57} 58declare module "Object/At" { 59 import { Key } from "Any/Key"; 60 import { Boolean } from "Boolean/Boolean"; 61 62 type AtStrict<O extends object, K extends Key> = [K & keyof O] extends [never] ? never : O[K & keyof O]; 63 64 type AtLoose<O extends object, K extends Key> = O extends unknown ? AtStrict<O, K> : never; 65 66 export type At<O extends object, K extends Key, strict extends Boolean = 1> = { 67 1: AtStrict<O, K>; 68 0: AtLoose<O, K>; 69 }[strict]; 70} 71declare module "Boolean/Boolean" { 72 export type Boolean = True | False; 73 74 export type True = 1; 75 76 export type False = 0; 77} 78declare module "Boolean/Not" { 79 import { Boolean } from "Boolean/Boolean"; 80 81 export type Not<B extends Boolean> = { 82 0: 1; 83 1: 0; 84 }[B]; 85} 86declare module "Union/Has" { 87 import { Union } from "Union/Union"; 88 import { Not } from "Boolean/Not"; 89 import { Extends } from "Any/Extends"; 90 91 export type Has<U extends Union, U1 extends Union> = Not<Extends<Exclude<U1, U>, U1>>; 92} 93declare module "Union/Union" { 94 export type Union = any; 95} 96declare module "Union/Exclude" { 97 import { Union } from "Union/Union"; 98 99 export type Exclude<U extends Union, M extends Union> = U extends M ? never : U; 100} 101declare module "Any/_Internal" { 102 import { _NumberOf } from "Number/NumberOf"; 103 104 export type Match = 'default' | 'implements->' | '<-implements' | 'extends->' | '<-extends' | 'equals'; 105 106 export type NumberOf<N extends any> = N extends number ? _NumberOf<N> : N; 107} 108declare module "Any/Implements" { 109 import { Extends } from "Any/Extends"; 110 111 export type Implements<A1 extends any, A2 extends any> = Extends<A1, A2> extends 1 ? 1 : 0; 112} 113declare module "Any/Key" { 114 export type Key = string | number | symbol; 115} 116declare module "Union/Keys" { 117 import { Union } from "Union/Union"; 118 import { Key } from "Any/Key"; 119 120 export type Keys<U extends Union> = (U extends unknown ? keyof U : never) & Key; 121} 122declare module "List/ObjectOf" { 123 import { _Omit } from "Object/Omit"; 124 import { Has } from "Union/Has"; 125 import { At } from "Object/At"; 126 import { List } from "List/List"; 127 128 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; 129 130 export type ObjectOf<L extends object> = L extends unknown ? _ObjectOf<L> : never; 131} 132declare module "List/Keys" { 133 import { Exclude } from "Union/Exclude"; 134 import { List } from "List/List"; 135 import { Keys as UKeys } from "Union/Keys"; 136 137 export type Keys<L extends List> = Exclude<UKeys<L>, keyof any[]> | number; 138} 139declare module "Object/Merge" { 140 import { _Omit } from "Object/Omit"; 141 import { At } from "Object/At"; 142 import { Compute } from "Any/Compute"; 143 import { Depth } from "Object/_Internal"; 144 import { Kind } from "Any/Kind"; 145 146 export type MergeFlat<O extends object, O1 extends object> = Compute<O & _Omit<O1, keyof O>>; 147 148 export type MergeDeep<O, O1> = (Kind<(O | O1)> extends 'object' ? MergeFlat<O & {}, O1 & {}> extends infer M ? { 149 [K in keyof M]: MergeDeep<M[K], At<O1 & {}, K>>; 150 } & {} : never : O); 151 152 export type Merge<O extends object, O1 extends object, depth extends Depth = 'flat'> = { 153 'flat': MergeFlat<O, O1>; 154 'deep': MergeDeep<O, O1>; 155 }[depth]; 156} 157declare module "Union/NonNullable" { 158 import { Exclude } from "Union/Exclude"; 159 import { Union } from "Union/Union"; 160 161 export type NonNullable<U extends Union> = Exclude<U, undefined | null>; 162} 163declare module "Object/ListOf" { 164 import { IterationOf } from "Iteration/IterationOf"; 165 import { Iteration } from "Iteration/Iteration"; 166 import { Cast } from "Any/Cast"; 167 import { Key } from "Iteration/Key"; 168 import { Next } from "Iteration/Next"; 169 import { _Append } from "List/Append"; 170 import { Exclude } from "Union/Exclude"; 171 import { List } from "List/List"; 172 import { Extends } from "Any/Extends"; 173 174 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; 175 176 type __ListOf<O extends object, K, LN extends List = [], I extends Iteration = IterationOf<'0'>> = { 177 0: __ListOf<O, Exclude<K, Key<I>>, PickIfEntry<O, LN, I>, Next<I>>; 178 1: LN; 179 }[Extends<[K], [never]>]; 180 181 export type _ListOf<O extends object> = __ListOf<O, keyof O> extends infer X ? Cast<X, List> : never; 182 183 export type ListOf<O extends object> = O extends unknown ? _ListOf<O> : never; 184} 185declare module "Object/NonNullable" { 186 import { MergeFlat } from "Object/Merge"; 187 import { NonNullable as UNonNullable } from "Union/NonNullable"; 188 import { Depth } from "Object/_Internal"; 189 import { Pick } from "Object/Pick"; 190 import { Key } from "Any/Key"; 191 import { Implements } from "Any/Implements"; 192 import { Keys } from "Object/Keys"; 193 194 export type NonNullableFlat<O> = { 195 [K in keyof O]: UNonNullable<O[K]>; 196 } & {}; 197 198 export type NonNullableDeep<O> = { 199 [K in keyof O]: NonNullableDeep<UNonNullable<O[K]>>; 200 }; 201 202 type NonNullablePart<O extends object, depth extends Depth> = { 203 'flat': NonNullableFlat<O>; 204 'deep': NonNullableDeep<O>; 205 }[depth]; 206 207 export type NonNullable<O extends object, K extends Key = Key, depth extends Depth = 'flat'> = { 208 1: NonNullablePart<O, depth>; 209 0: MergeFlat<NonNullablePart<Pick<O, K>, depth>, O>; 210 }[Implements<Keys<O>, K>] & {}; 211} 212declare module "Object/Overwrite" { 213 export type Overwrite<O extends object, O1 extends object> = { 214 [K in keyof O]: K extends keyof O1 ? O1[K] : O[K]; 215 } & {}; 216} 217declare module "Number/_Internal" { 218 import { IterationMap } from "Iteration/IterationOf"; 219 import { Format } from "Iteration/Format"; 220 221 export type Formats = 'b' | 'n' | 's'; 222 223 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'; 224 225 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'; 226 227 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'; 228 229 export type Numbers = { 230 'string': { 231 'all': Format<IterationMap[KnownIterationMapKeys], 's'>; 232 '+': Format<IterationMap[PositiveIterationKeys], 's'>; 233 '-': Format<IterationMap[NegativeIterationKeys], 's'>; 234 '0': Format<IterationMap['0'], 's'>; 235 }; 236 'number': { 237 'all': Format<IterationMap[KnownIterationMapKeys], 'n'>; 238 '+': Format<IterationMap[PositiveIterationKeys], 'n'>; 239 '-': Format<IterationMap[NegativeIterationKeys], 'n'>; 240 '0': Format<IterationMap['0'], 'n'>; 241 }; 242 }; 243} 244declare module "Number/Number" { 245 export type Number = string; 246} 247declare module "Iteration/_Internal" { 248 export type Formats = 'n' | 's'; 249 export type Way = '->' | '<-'; 250} 251declare module "List/Prepend" { 252 import { List } from "List/List"; 253 254 export type Prepend<L extends List, A extends any> = ((head: A, ...args: L) => any) extends ((...args: infer U) => any) ? U : L; 255} 256declare module "List/_Internal" { 257 import { Overwrite } from "Object/Overwrite"; 258 import { List } from "List/List"; 259 260 export type Naked<L extends List> = Overwrite<Required<L>, L>; 261} 262declare module "List/Tail" { 263 import { List } from "List/List"; 264 265 export type Tail<L extends List> = ((...t: L) => any) extends ((head: any, ...tail: infer LTail) => any) ? LTail : never; 266} 267declare module "Iteration/Format" { 268 import { Iteration } from "Iteration/Iteration"; 269 import { Formats } from "Iteration/_Internal"; 270 271 export type Format<I extends Iteration, fmt extends Formats> = { 272 's': I[2]; 273 'n': I[3]; 274 }[fmt]; 275} 276declare module "Iteration/Pos" { 277 import { Iteration } from "Iteration/Iteration"; 278 import { Format } from "Iteration/Format"; 279 280 export type Pos<I extends Iteration> = Format<I, 'n'>; 281} 282declare module "List/Append" { 283 import { _Concat } from "List/Concat"; 284 import { List } from "List/List"; 285 286 export type _Append<L extends List, A extends any> = _Concat<L, [A]>; 287 288 export type Append<L extends List, A extends any> = L extends unknown ? A extends unknown ? _Append<L, A> : never : never; 289} 290declare module "List/Reverse" { 291 import { Prepend } from "List/Prepend"; 292 import { Pos } from "Iteration/Pos"; 293 import { Next } from "Iteration/Next"; 294 import { Length } from "List/Length"; 295 import { IterationOf } from "Iteration/IterationOf"; 296 import { Iteration } from "Iteration/Iteration"; 297 import { Cast } from "Any/Cast"; 298 import { List } from "List/List"; 299 import { Naked } from "List/_Internal"; 300 import { Extends } from "Any/Extends"; 301 302 type __Reverse<L extends List, LO extends List, I extends Iteration = IterationOf<'0'>> = { 303 0: __Reverse<L, Prepend<LO, L[Pos<I>]>, Next<I>>; 304 1: LO; 305 }[Extends<Pos<I>, Length<L>>]; 306 307 export type _Reverse<L extends List, LO extends List = []> = __Reverse<Naked<L>, LO> extends infer X ? Cast<X, List> : never; 308 309 export type Reverse<L extends List, LO extends List = []> = L extends unknown ? LO extends unknown ? _Reverse<L, LO> : never : never; 310} 311declare module "List/Concat" { 312 import { _Reverse } from "List/Reverse"; 313 import { List } from "List/List"; 314 315 export type _Concat<L extends List, L1 extends List> = _Reverse<_Reverse<L>, L1>; 316 317 export type Concat<L extends List, L1 extends List> = L extends unknown ? L1 extends L1 ? _Concat<L, L1> : never : never; 318} 319declare module "List/Drop" { 320 import { Tail } from "List/Tail"; 321 import { Cast } from "Any/Cast"; 322 import { IterationOf } from "Iteration/IterationOf"; 323 import { Iteration } from "Iteration/Iteration"; 324 import { Number } from "Number/Number"; 325 import { Way } from "Iteration/_Internal"; 326 import { List } from "List/List"; 327 import { Pos } from "Iteration/Pos"; 328 import { Prev } from "Iteration/Prev"; 329 import { Prepend } from "List/Prepend"; 330 import { Naked } from "List/_Internal"; 331 import { Extends } from "Any/Extends"; 332 333 type DropForth<L extends List, N extends Iteration> = { 334 0: DropForth<Tail<L>, Prev<N>>; 335 1: L; 336 }[Extends<0, Pos<N>>]; 337 338 type DropBack<L extends List, N extends Iteration, I extends Iteration = Prev<N>, LN extends List = []> = { 339 0: DropBack<L, N, Prev<I>, Prepend<LN, L[Pos<I>]>>; 340 1: LN; 341 }[Extends<-1, Pos<I>>]; 342 343 type __Drop<L extends List, N extends Iteration, way extends Way = '->'> = { 344 '->': DropForth<L, N>; 345 '<-': DropBack<L, N>; 346 }[way]; 347 348 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; 349 350 export type Drop<L extends List, N extends Number, way extends Way = '->'> = L extends unknown ? N extends unknown ? _Drop<L, N, way> : never : never; 351} 352declare module "List/Length" { 353 import { NumberOf } from "Number/NumberOf"; 354 import { Formats } from "Iteration/_Internal"; 355 import { List } from "List/List"; 356 357 export type Length<L extends List, fmt extends Formats = 'n'> = { 358 's': NumberOf<L['length']>; 359 'n': L['length']; 360 }[fmt]; 361} 362declare module "Iteration/Next" { 363 import { IterationMap } from "Iteration/IterationOf"; 364 import { Iteration } from "Iteration/Iteration"; 365 366 export type Next<I extends Iteration> = IterationMap[I[1]]; 367} 368declare module "Any/Cast" { 369 export type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2; 370} 371declare module "Function/Parameters" { 372 import { Function } from "Function/Function"; 373 374 export type Parameters<F extends Function> = F extends ((...args: infer L) => any) ? L : never; 375} 376declare module "Function/Return" { 377 import { Function } from "Function/Function"; 378 379 export type Return<F extends Function> = F extends ((...args: any[]) => infer R) ? R : never; 380} 381declare module "Iteration/Prev" { 382 import { IterationMap } from "Iteration/IterationOf"; 383 import { Iteration } from "Iteration/Iteration"; 384 385 export type Prev<I extends Iteration> = IterationMap[I[0]]; 386} 387declare module "Number/NumberOf" { 388 import { IterationMap } from "Iteration/IterationOf"; 389 import { Key } from "Iteration/Key"; 390 import { Pos } from "Iteration/Pos"; 391 import { Numbers } from "Number/_Internal"; 392 393 export type _NumberOf<N extends number> = { 394 [K in keyof IterationMap]: Pos<IterationMap[K]> extends N ? Key<IterationMap[K]> : never; 395 }[keyof IterationMap]; 396 397 export type NumberOf<N extends number> = N extends Numbers['number']['all'] ? _NumberOf<N> : string; 398} 399declare module "Object/_Internal" { 400 export type Modx = ['?' | '!', 'W' | 'R']; 401 402 export type Depth = 'flat' | 'deep'; 403 404 export type Empty<O extends object> = { 405 [K in keyof O]: undefined; 406 }; 407} 408declare module "Iteration/IterationOf" { 409 import { Number } from "Number/Number"; 410 411 export type IterationMap = { 412 '-40': ['__', '-39', '-40', -40, '-']; 413 '-39': ['-40', '-38', '-39', -39, '-']; 414 '-38': ['-39', '-37', '-38', -38, '-']; 415 '-37': ['-38', '-36', '-37', -37, '-']; 416 '-36': ['-37', '-35', '-36', -36, '-']; 417 '-35': ['-36', '-34', '-35', -35, '-']; 418 '-34': ['-35', '-33', '-34', -34, '-']; 419 '-33': ['-34', '-32', '-33', -33, '-']; 420 '-32': ['-33', '-31', '-32', -32, '-']; 421 '-31': ['-32', '-30', '-31', -31, '-']; 422 '-30': ['-31', '-29', '-30', -30, '-']; 423 '-29': ['-30', '-28', '-29', -29, '-']; 424 '-28': ['-29', '-27', '-28', -28, '-']; 425 '-27': ['-28', '-26', '-27', -27, '-']; 426 '-26': ['-27', '-25', '-26', -26, '-']; 427 '-25': ['-26', '-24', '-25', -25, '-']; 428 '-24': ['-25', '-23', '-24', -24, '-']; 429 '-23': ['-24', '-22', '-23', -23, '-']; 430 '-22': ['-23', '-21', '-22', -22, '-']; 431 '-21': ['-22', '-20', '-21', -21, '-']; 432 '-20': ['-21', '-19', '-20', -20, '-']; 433 '-19': ['-20', '-18', '-19', -19, '-']; 434 '-18': ['-19', '-17', '-18', -18, '-']; 435 '-17': ['-18', '-16', '-17', -17, '-']; 436 '-16': ['-17', '-15', '-16', -16, '-']; 437 '-15': ['-16', '-14', '-15', -15, '-']; 438 '-14': ['-15', '-13', '-14', -14, '-']; 439 '-13': ['-14', '-12', '-13', -13, '-']; 440 '-12': ['-13', '-11', '-12', -12, '-']; 441 '-11': ['-12', '-10', '-11', -11, '-']; 442 '-10': ['-11', '-9', '-10', -10, '-']; 443 '-9': ['-10', '-8', '-9', -9, '-']; 444 '-8': ['-9', '-7', '-8', -8, '-']; 445 '-7': ['-8', '-6', '-7', -7, '-']; 446 '-6': ['-7', '-5', '-6', -6, '-']; 447 '-5': ['-6', '-4', '-5', -5, '-']; 448 '-4': ['-5', '-3', '-4', -4, '-']; 449 '-3': ['-4', '-2', '-3', -3, '-']; 450 '-2': ['-3', '-1', '-2', -2, '-']; 451 '-1': ['-2', '0', '-1', -1, '-']; 452 '0': ['-1', '1', '0', 0, '0']; 453 '1': ['0', '2', '1', 1, '+']; 454 '2': ['1', '3', '2', 2, '+']; 455 '3': ['2', '4', '3', 3, '+']; 456 '4': ['3', '5', '4', 4, '+']; 457 '5': ['4', '6', '5', 5, '+']; 458 '6': ['5', '7', '6', 6, '+']; 459 '7': ['6', '8', '7', 7, '+']; 460 '8': ['7', '9', '8', 8, '+']; 461 '9': ['8', '10', '9', 9, '+']; 462 '10': ['9', '11', '10', 10, '+']; 463 '11': ['10', '12', '11', 11, '+']; 464 '12': ['11', '13', '12', 12, '+']; 465 '13': ['12', '14', '13', 13, '+']; 466 '14': ['13', '15', '14', 14, '+']; 467 '15': ['14', '16', '15', 15, '+']; 468 '16': ['15', '17', '16', 16, '+']; 469 '17': ['16', '18', '17', 17, '+']; 470 '18': ['17', '19', '18', 18, '+']; 471 '19': ['18', '20', '19', 19, '+']; 472 '20': ['19', '21', '20', 20, '+']; 473 '21': ['20', '22', '21', 21, '+']; 474 '22': ['21', '23', '22', 22, '+']; 475 '23': ['22', '24', '23', 23, '+']; 476 '24': ['23', '25', '24', 24, '+']; 477 '25': ['24', '26', '25', 25, '+']; 478 '26': ['25', '27', '26', 26, '+']; 479 '27': ['26', '28', '27', 27, '+']; 480 '28': ['27', '29', '28', 28, '+']; 481 '29': ['28', '30', '29', 29, '+']; 482 '30': ['29', '31', '30', 30, '+']; 483 '31': ['30', '32', '31', 31, '+']; 484 '32': ['31', '33', '32', 32, '+']; 485 '33': ['32', '34', '33', 33, '+']; 486 '34': ['33', '35', '34', 34, '+']; 487 '35': ['34', '36', '35', 35, '+']; 488 '36': ['35', '37', '36', 36, '+']; 489 '37': ['36', '38', '37', 37, '+']; 490 '38': ['37', '39', '38', 38, '+']; 491 '39': ['38', '40', '39', 39, '+']; 492 '40': ['39', '__', '40', 40, '+']; 493 '__': ['__', '__', string, number, '-' | '0' | '+']; 494 }; 495 496 export type IterationOf<N extends Number> = N extends keyof IterationMap ? IterationMap[N] : IterationMap['__']; 497} 498declare module "Iteration/Iteration" { 499 import { IterationMap } from "Iteration/IterationOf"; 500 501 export type Iteration = [keyof IterationMap, keyof IterationMap, string, number, '-' | '0' | '+']; 502} 503declare module "Iteration/Key" { 504 import { Iteration } from "Iteration/Iteration"; 505 import { Format } from "Iteration/Format"; 506 507 export type Key<I extends Iteration> = Format<I, 's'>; 508} 509declare module "List/NonNullable" { 510 import { Depth } from "Object/_Internal"; 511 import { NonNullable as ONonNullable } from "Object/NonNullable"; 512 import { ListOf } from "Object/ListOf"; 513 import { Cast } from "Any/Cast"; 514 import { Key } from "Any/Key"; 515 import { ObjectOf } from "List/ObjectOf"; 516 import { Implements } from "Any/Implements"; 517 import { Keys } from "List/Keys"; 518 import { List } from "List/List"; 519 import { NumberOf } from "Any/_Internal"; 520 521 export type NonNullable<L extends List, K extends Key = Key, depth extends Depth = 'flat'> = { 522 1: Cast<ONonNullable<L, Key, depth>, List>; 523 0: ListOf<ONonNullable<ObjectOf<L>, NumberOf<K>, depth>>; 524 }[Implements<Keys<L>, K>] & {}; 525} 526declare module "Any/Type" { 527 const symbol: unique symbol; 528 529 export type Type<A extends any, Id extends string> = A & { 530 [K in typeof symbol]: Id; 531 }; 532} 533declare module "Any/x" { 534 import { Type } from "Any/Type"; 535 536 export type x = Type<{}, 'x'>; 537} 538declare module "List/List" { 539 540 export type List<A = any> = ReadonlyArray<A>; 541} 542declare module "Function/Function" { 543 import { List } from "List/List"; 544 545 export interface Function<P extends List = any, R extends any = any> { 546 (...args: P): R; 547 } 548} 549declare module "Any/Extends" { 550 export type Extends<A1 extends any, A2 extends any> = [A1] extends [never] ? 0 : A1 extends A2 ? 1 : 0; 551} 552 553declare module "Function/Curry" { 554 import { Pos } from "Iteration/Pos"; 555 import { _Append } from "List/Append"; 556 import { _Concat } from "List/Concat"; 557 import { _Drop } from "List/Drop"; 558 import { Length } from "List/Length"; 559 import { Next } from "Iteration/Next"; 560 import { Cast } from "Any/Cast"; 561 import { Parameters } from "Function/Parameters"; 562 import { Return } from "Function/Return"; 563 import { IterationOf } from "Iteration/IterationOf"; 564 import { Iteration } from "Iteration/Iteration"; 565 import { Key } from "Iteration/Key"; 566 import { NonNullable } from "List/NonNullable"; 567 import { x } from "Any/x"; 568 import { List } from "List/List"; 569 import { Function } from "Function/Function"; 570 import { Extends } from "Any/Extends"; 571 572 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; 573 574 type _GapsOf<L1 extends List, L2 extends List, LN extends List = [], I extends Iteration = IterationOf<'0'>> = { 575 0: _GapsOf<L1, L2, GapOf<L1, L2, LN, I>, Next<I>>; 576 1: _Concat<LN, _Drop<L2, Key<I>>>; 577 }[Extends<Pos<I>, Length<L1>>]; 578 579 type GapsOf<L1 extends List, L2 extends List> = _GapsOf<L1, L2> extends infer X ? Cast<X, List> : never; 580 581 type Gaps<L extends List> = NonNullable<{ 582 [K in keyof L]?: L[K] | x; 583 }>; 584 585 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; 586} 587 588 589 590 591