sindresorhus/type-fest

`Proposal`: add option with exclude/keep specified type on deep type

Open

#862 aperta il 12 apr 2024

Vedi su GitHub
 (5 commenti) (0 reazioni) (1 assegnatario)TypeScript (471 fork)batch import
help wantedtype addition

Metriche repository

Star
 (12.328 star)
Metriche merge PR
 (Merge medio 4g 18h) (9 PR mergiate in 30 g)

Descrizione

Look at this scene

I have a type Item that wrapped with some util type, and I want get a simplify Item, like:

import type { SimplifyDeep } from 'type-fest/source/merge-deep'

type SimplifyItem = SimplifyDeep<Item>
// => expect type SimplifyItem = { name: string, color: THREE.Color }

but actual rsult is:

import type { SimplifyDeep } from 'type-fest/source/merge-deep'

type SimplifyItem = SimplifyDeep<Item>
/**
type SimplifyItem = { 
    name: string,
    color: {
            readonly isColor: true;
            r: number;
            g: number;
            b: number;
            set: (color: string | number | Color) => Color;
            ... 31 more ...;
            toArray: {
                ...;
            };
        };
}
*/

so maybe we can add a exclude type option ( or named keep ) on Deep type like:

import type { SimplifyDeep } from 'type-fest/source/merge-deep'

type SimplifyItem = SimplifyDeep<Item, { exclude: THREE.Color }>
// => expect type SimplifyItem = { name: string, color: THREE.Color }

It can also resolve scene conflicts between users, such as one want recursive into HTMLElemet, anther one want keep HTMLElemet

Related comment: https://github.com/sindresorhus/type-fest/issues/651#issuecomment-1803324362 Related issue: #651

Guida contributor