Type alias MatchingOutput<S>

MatchingOutput<S>: S extends string
    ? InferTypeFromValue<S> extends never
        ? string
        : InferTypeFromValue<S>
    : S extends readonly string[]
        ? {
            [K in S[number]]: InferTypeFromKey<K> extends never
                ? string
                : InferTypeFromKey<K>
        }
        : S extends Record<string, string>
            ? {
                [K in keyof S]: InferTypeFromSpecEntry<S, K>
            }
            : never

Infers the expected output type for given Specs.

Type Parameters

Example

const stringSpecs = 'Items to buy (array of strings)';
type StringSpecsOutput = MatchingOutput<typeof stringSpecs>;
// expected: string[]

Example

const arraySpecs = ['groceriesArray', 'isPaid', 'notes'];
type ArraySpecsOutput = MatchingOutput<typeof arraySpecs>;
// expected: { groceriesArray: string[], isPaid: boolean, notes: string }

Example

const dictSpecs = {
groceries: 'items to buy (array of strings)',
unitPrices: 'unit prices for all items (array of numbers)',
total: 'amount to pay (number)',
isPaid: 'true if paid',
notes: 'arbitrary notes'
};
type DictSpecsOutput = MatchingOutput<typeof dictSpecs>;
// expected: { groceries: string[], unitPrices: number[], total: number, isPaid: boolean, notes: string }

Generated using TypeDoc