|
| 1 | +tests/cases/compiler/specedNoStackBlown.ts(7,50): error TS2315: Type 'SpecValue' is not generic. |
| 2 | +tests/cases/compiler/specedNoStackBlown.ts(7,84): error TS2315: Type 'SpecValue' is not generic. |
| 3 | +tests/cases/compiler/specedNoStackBlown.ts(22,29): error TS2315: Type 'SpecObject' is not generic. |
| 4 | +tests/cases/compiler/specedNoStackBlown.ts(25,13): error TS2456: Type alias 'SpecObject' circularly references itself. |
| 5 | +tests/cases/compiler/specedNoStackBlown.ts(25,81): error TS2315: Type 'SpecValue' is not generic. |
| 6 | +tests/cases/compiler/specedNoStackBlown.ts(27,13): error TS2456: Type alias 'SpecValue' circularly references itself. |
| 7 | +tests/cases/compiler/specedNoStackBlown.ts(30,78): error TS2315: Type 'SpecObject' is not generic. |
| 8 | + |
| 9 | + |
| 10 | +==== tests/cases/compiler/specedNoStackBlown.ts (7 errors) ==== |
| 11 | + // Type definitions for spected 0.7 |
| 12 | + // Project: https://github.com/25th-floor/spected |
| 13 | + // Definitions by: Benjamin Makus <https://github.com/benneq> |
| 14 | + // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 15 | + // TypeScript Version: 2.8 |
| 16 | + |
| 17 | + declare function spected<ROOTINPUT, SPEC extends SpecValue<ROOTINPUT, ROOTINPUT> = SpecValue<ROOTINPUT, ROOTINPUT>>(spec: SPEC, input: ROOTINPUT): Result<ROOTINPUT, SPEC>; |
| 18 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 19 | +!!! error TS2315: Type 'SpecValue' is not generic. |
| 20 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 | +!!! error TS2315: Type 'SpecValue' is not generic. |
| 22 | + |
| 23 | + type Predicate<INPUT, ROOTINPUT> = (value: INPUT, inputs: ROOTINPUT) => boolean; |
| 24 | + |
| 25 | + type ErrorMsg<INPUT> = |
| 26 | + | (string | number | boolean | symbol | null | undefined | object) |
| 27 | + | ((value: INPUT, field: string) => any); |
| 28 | + |
| 29 | + export type Spec<INPUT, ROOTINPUT = any> = [Predicate<INPUT, ROOTINPUT>, ErrorMsg<INPUT>]; |
| 30 | + |
| 31 | + export type SpecArray<INPUT, ROOTINPUT = any> = Array<Spec<INPUT, ROOTINPUT>>; |
| 32 | + |
| 33 | + export type SpecFunction<INPUT, ROOTINPUT = any> = [INPUT] extends [ReadonlyArray<infer U>] |
| 34 | + ? (value: INPUT) => ReadonlyArray<SpecArray<U, ROOTINPUT>> |
| 35 | + : [INPUT] extends [object] |
| 36 | + ? (value: INPUT) => SpecObject<INPUT, ROOTINPUT> |
| 37 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 38 | +!!! error TS2315: Type 'SpecObject' is not generic. |
| 39 | + : (value: INPUT) => SpecArray<INPUT, ROOTINPUT>; |
| 40 | + |
| 41 | + export type SpecObject<INPUT, ROOTINPUT = any> = Partial<{[key in keyof INPUT]: SpecValue<INPUT[key], ROOTINPUT>}>; |
| 42 | + ~~~~~~~~~~ |
| 43 | +!!! error TS2456: Type alias 'SpecObject' circularly references itself. |
| 44 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 45 | +!!! error TS2315: Type 'SpecValue' is not generic. |
| 46 | + |
| 47 | + export type SpecValue<INPUT, ROOTINPUT = any> = [INPUT] extends [ReadonlyArray<any>] |
| 48 | + ~~~~~~~~~ |
| 49 | +!!! error TS2456: Type alias 'SpecValue' circularly references itself. |
| 50 | + ? SpecArray<INPUT, ROOTINPUT> | SpecFunction<INPUT, ROOTINPUT> |
| 51 | + : [INPUT] extends [object] |
| 52 | + ? SpecArray<INPUT, ROOTINPUT> | SpecFunction<INPUT, ROOTINPUT> | SpecObject<INPUT, ROOTINPUT> |
| 53 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 54 | +!!! error TS2315: Type 'SpecObject' is not generic. |
| 55 | + : SpecArray<INPUT, ROOTINPUT> | SpecFunction<INPUT, ROOTINPUT>; |
| 56 | + |
| 57 | + export type Result<INPUT, SPEC> = {[key in keyof INPUT]: true | any[] | Result<INPUT[key], any>}; |
| 58 | + |
| 59 | + export default spected; |
| 60 | + |
0 commit comments