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 should properly set type of objects in arrays #883

Closed
bvandercar-vt opened this issue Jun 3, 2024 · 3 comments
Closed

schema should properly set type of objects in arrays #883

bvandercar-vt opened this issue Jun 3, 2024 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@bvandercar-vt
Copy link

bvandercar-vt commented Jun 3, 2024

Current implementation:

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

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

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

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

Should be:

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

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Jun 4, 2024
@grigorischristainas
Copy link
Contributor

@sindresorhus, @bvandercar-vt, do you think the implementation should change for arrays in general, or just for arrays of objects?

Given the following example, based on the current implementation:

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

interface Users {
	names: Array<string>;
}

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

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

should userMaskSettings be changed as follows ?

const userMaskSettings: UserMask = {
	names: ['mask']
}

@bvandercar-vt
Copy link
Author

@grigorischristainas that change makes sense to me.

@sindresorhus
Copy link
Owner

#887

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants