Sha256: 8be5c5be3dbf0003a628f99ad870e31bebc2364c28ea3b96231089a94e09f7a6

Contents?: true

Size: 1.66 KB

Versions: 25

Compression:

Stored size: 1.66 KB

Contents

/**
Create a deep version of another object type where property values are recursively replaced into a given value type.

Use-cases:
- Form validation: Define how each field should be validated.
- Form settings: Define configuration for input fields.
- Parsing: Define types that specify special behavior for specific fields.

@example
```
import type {Schema} from 'type-fest';

interface User {
	id: string;
	name: {
		firstname: string;
		lastname: string;
	};
	created: Date;
	active: boolean;
	passwordHash: string;
}

type UserMask = Schema<User, 'mask' | 'hide' | 'show'>;

const userMaskSettings: UserMask = {
	id: 'show',
	name: {
		firstname: 'show',
		lastname: 'mask',
	},
	phoneNumbers: 'mask',
	created: 'show',
	active: 'show',
	passwordHash: 'hide',
}
```

@category Object
*/
export type Schema<ObjectType, ValueType> = ObjectType extends string
	? ValueType
	: ObjectType extends Map<unknown, unknown>
	? ValueType
	: ObjectType extends Set<unknown>
	? ValueType
	: ObjectType extends ReadonlyMap<unknown, unknown>
	? ValueType
	: ObjectType extends ReadonlySet<unknown>
	? ValueType
	: ObjectType extends readonly unknown[]
	? ValueType
	: ObjectType extends unknown[]
	? ValueType
	: ObjectType extends (...arguments: unknown[]) => unknown
	? ValueType
	: ObjectType extends Date
	? ValueType
	: ObjectType extends Function
	? ValueType
	: ObjectType extends RegExp
	? ValueType
	: ObjectType extends object
	? SchemaObject<ObjectType, ValueType>
	: ValueType;

/**
Same as `Schema`, but accepts only `object`s as inputs. Internal helper for `Schema`.
*/
type SchemaObject<ObjectType extends object, K> = {
	[KeyType in keyof ObjectType]: Schema<ObjectType[KeyType], K> | K;
};

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.52 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.51 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.50 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.49 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.48 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.47 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.46 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.45 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.44 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.43 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.42 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.41 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.40 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.39 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.38 node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.32 node_modules/boxen/node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.31 node_modules/boxen/node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.30 node_modules/boxen/node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.29 node_modules/boxen/node_modules/type-fest/source/schema.d.ts
immosquare-cleaner-0.1.28 node_modules/boxen/node_modules/type-fest/source/schema.d.ts