@snailicide/build-config / utilities / LiteralToPrimitiveDeep
LiteralToPrimitiveDeep<T>
ts
type LiteralToPrimitiveDeep<T> = T extends object ? T extends infer U[] ? LiteralToPrimitiveDeep<U>[] : { [K in keyof OmitIndexSignature<T>]: LiteralToPrimitiveDeep<T[K]> } : LiteralToPrimitive<T>;Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/literal-to-primitive-deep.d.ts:30
Like LiteralToPrimitive except it converts literal types inside an object or array deeply.
For example, given a constant object, it returns a new object type with the same keys but with all the values converted to primitives.
Type Parameters
| Type Parameter |
|---|
T |
See
LiteralToPrimitive
Use-case: Deal with data that is imported from a JSON file.
Example
import type {LiteralToPrimitiveDeep, TsConfigJson} from 'type-fest';
import tsconfig from 'path/to/tsconfig.json';
function doSomethingWithTSConfig(config: LiteralToPrimitiveDeep<TsConfigJson>) { ... }
// No casting is needed to pass the type check
doSomethingWithTSConfig(tsconfig);
// If LiteralToPrimitiveDeep is not used, you need to cast the imported data like this:
doSomethingWithTSConfig(tsconfig as TsConfigJson);