mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Merge pull request #18475 from strapi/ts/replace-util
This commit is contained in:
commit
ea26b0dc3f
@ -30,6 +30,9 @@ type Values = Utils.Object.Values<{ foo: 'bar'; bar: 'foo'; foobar: 2 }>;
|
||||
type ValuesNever = Utils.Object.Values<never>;
|
||||
type ValuesContainNever = Utils.Object.Values<{ foo: 'bar'; bar: 'foo'; foobar: never }>;
|
||||
|
||||
// Replace
|
||||
type Replace = Utils.Object.Replace<{ foo: 'bar'; bar: 'foo' }, { foo: 2 }>;
|
||||
|
||||
export {
|
||||
// KeysBy
|
||||
KeysByString,
|
||||
@ -56,4 +59,7 @@ export {
|
||||
Values,
|
||||
ValuesNever,
|
||||
ValuesContainNever,
|
||||
|
||||
// Replace
|
||||
Replace,
|
||||
};
|
||||
|
@ -77,4 +77,15 @@ describe('Utils.Object', () => {
|
||||
type('ValuesNever').isNever();
|
||||
type('ValuesContainNever').isUnion([t.stringLiteral('foo'), t.stringLiteral('bar')]);
|
||||
});
|
||||
|
||||
test.skip('Replace', () => {
|
||||
// const expectedResultType = t.object({
|
||||
// properties: {
|
||||
// foo: t.numberLiteral(2),
|
||||
// bar: t.stringLiteral('foo'),
|
||||
// },
|
||||
// });
|
||||
// // TODO: Fix object type check
|
||||
// type('Replace').isObject(expectedResultType);
|
||||
});
|
||||
});
|
||||
|
@ -64,3 +64,15 @@ export type DeepPartial<TObject> = TObject extends object
|
||||
[TKey in keyof TObject]?: DeepPartial<TObject[TKey]>;
|
||||
}
|
||||
: TObject;
|
||||
|
||||
/**
|
||||
* Replace the keys of an object with the keys of another object
|
||||
*
|
||||
* @example
|
||||
* type X = Replace<{ foo: number, bar: number}, { foo: string }>
|
||||
* // { foo: string, bar: number }
|
||||
*/
|
||||
export type Replace<
|
||||
TObject extends object,
|
||||
TNew extends Partial<{ [key in keyof TObject]: unknown }>
|
||||
> = Omit<TObject, keyof TNew> & TNew;
|
||||
|
Loading…
x
Reference in New Issue
Block a user