( a: A, b: B, operation = "add", )
| 349 | // // Run-time type helper functions |
| 350 | |
| 351 | export function addOutputType<A extends AllValueTypes, B extends AllValueTypes>( |
| 352 | a: A, |
| 353 | b: B, |
| 354 | operation = "add", |
| 355 | ): AddOutput<A, B> { |
| 356 | const error = () => { |
| 357 | throw new Error(`Invalid ${operation} types: ${a}, ${b}`); |
| 358 | }; |
| 359 | // @ts-ignore |
| 360 | if (a === b) return a as AddOutput<A, B>; |
| 361 | if (a === "int") { |
| 362 | if (isIntType(b)) return b as AddOutput<A, B>; |
| 363 | error(); |
| 364 | } |
| 365 | if (b === "int") { |
| 366 | if (isIntType(a)) return a as AddOutput<A, B>; |
| 367 | error(); |
| 368 | } |
| 369 | if (a === "uint") { |
| 370 | if (isUintType(b)) return b as AddOutput<A, B>; |
| 371 | error(); |
| 372 | } |
| 373 | if (b === "uint") { |
| 374 | if (isUintType(a)) return a as AddOutput<A, B>; |
| 375 | error(); |
| 376 | } |
| 377 | if (a === "float") { |
| 378 | if (isAllFloatType(b)) return b as AddOutput<A, B>; |
| 379 | error(); |
| 380 | } |
| 381 | if (b === "float") { |
| 382 | if (isAllFloatType(a)) return a as AddOutput<A, B>; |
| 383 | error(); |
| 384 | } |
| 385 | throw new Error(`Invalid ${operation} types: ${a}, ${b}`); |
| 386 | } |
| 387 | |
| 388 | export function subOutputType<A extends AllValueTypes, B extends AllValueTypes>( |
| 389 | a: A, |
no test coverage detected