Sha256: 85d63aaff358e8390b666a6bc68d3f56985f18764ab05f750cb67910f7bccb1a

Contents?: true

Size: 1.2 KB

Versions: 28

Compression:

Stored size: 1.2 KB

Contents

import type {Merge} from './merge';

/**
Override existing properties of the given type. Similar to `Merge`, but enforces that the original type has the properties you want to override.

This is useful when you want to override existing properties with a different type and make sure that these properties really exist in the original.

@example
```
type Foo = {
	a: string
	b: string
}
type Bar = OverrideProperties<Foo, {b: number}>
//=> {a: string, b: number}

type Baz = OverrideProperties<Foo, {c: number}>
// Error, type '{ c: number; }' does not satisfy the constraint '{ c: never; }'

type Fizz = OverrideProperties<Foo, {b: number; c: number}>
// Error, type '{ b: number; c: number; }' does not satisfy the constraint '{ b: number; c: never; }'
```

@category Object
*/
export type OverrideProperties<
	TOriginal,
	// This first bit where we use `Partial` is to enable autocomplete
	// and the second bit with the mapped type is what enforces that we don't try
	// to override properties that doesn't exist in the original type.
	TOverride extends Partial<Record<keyof TOriginal, unknown>> & {
		[Key in keyof TOverride]: Key extends keyof TOriginal
			? TOverride[Key]
			: never;
	},
> = Merge<TOriginal, TOverride>;

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.10 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.9 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.8 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts
clapton-0.0.7 lib/clapton/javascripts/node_modules/type-fest/source/override-properties.d.ts