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

Generate dot.notation access list for an object #715

Closed
fregante opened this issue Oct 20, 2023 · 3 comments
Closed

Generate dot.notation access list for an object #715

fregante opened this issue Oct 20, 2023 · 3 comments

Comments

@fregante
Copy link

fregante commented Oct 20, 2023

I don't know how common or how useful this would be, but it might be a companion to the Get/Set types.

const event = {
	user: {
		id: 123,
		name: 'giorgio'
	},
	action: 'delete'
} as const;

const id = get('user.id', event);
   // ^? number, typed via Get

get('user.state', event);
   // ^? Error, typed via advanced Get

This would also enable/export a "dot-notation keyof":

type DeepKeys = DeepKeyOf<typeof event>;
   // ^? ['user', 'user.id', 'user.name', 'action']

Real-life example:

https://github.com/pixiebrix/pixiebrix-app/blob/d30a53fe6f9e8baecc0b86356b4eab844e16d296/pixiebrix-app/src/pages/queryRegistry/exportQueryResult.ts#L8-L14

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
Copy link
Owner

Duplicate of #213

@sindresorhus sindresorhus marked this as a duplicate of #213 Oct 20, 2023
@fregante
Copy link
Author

fregante commented Oct 20, 2023

Oh good. I couldn't find it

Shouldn't #432 also be closed?

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2023
@sindresorhus
Copy link
Owner

Maybe, but it has more info.

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

No branches or pull requests

2 participants