Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema: Fix handling of arrays #887

Merged
merged 1 commit into from
Jun 15, 2024

Conversation

grigorischristainas
Copy link
Contributor

I opened this pull request based on #883. It includes a refactoring regarding the array handling. Although the issue concerns arrays of objects, I think it makes sense to generalize it to all arrays.

Given the following example:

import type {Schema} from 'type-fest';

interface Users {
	names: Array<string>;
        fullnames: Array<{
		firstname: string;
		lastname: string;
	}>;
}

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

Previous implementation:

const userMaskSettings: UserMask = {
	names: 'mask',
        fullnames: 'mask'
}

New implementation:

const userMaskSettings: UserMask = {
	names: ['mask'],
	fullnames: [
		{
			firstname: 'show',
			lastname: 'hide'
		}
	]
}

I would be happy to make any further adjustments as needed.

@sindresorhus sindresorhus changed the title schema: refactor array handling schema: Fix handling of arrays Jun 8, 2024
@sindresorhus sindresorhus changed the title schema: Fix handling of arrays Schema: Fix handling of arrays Jun 8, 2024
@sindresorhus sindresorhus merged commit c570ec2 into sindresorhus:main Jun 15, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants