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

# 22437 FlattenObject<T> #24411

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

yue1123
Copy link

@yue1123 yue1123 commented Mar 2, 2023

Implement a type FlattenObject<T> that deep flatten object to path and value type.

@jiangshanmeta
Copy link
Member

@yue1123 how to handle this cast:

const deep = {
  "a/b/c":true,
  a: {
    b: {
      c: 123,
      d: '123'
    }
  }
}

what's the final type for key "a/b/c"

@yue1123
Copy link
Author

yue1123 commented Mar 6, 2023

I haven't really considered this situation, maybe it can be handled with a union type, but in that case, this question should not be of medium difficulty😂

type finalType =
  | {
      'a/b/c': boolean
    }
  | {
      'a/b/c': number
      'a/b/d': string
    }

@antfu
Copy link
Member

antfu commented Mar 6, 2023

Maybe using . as the delimiter would be more intuitive?

@yue1123
Copy link
Author

yue1123 commented Mar 6, 2023

I think so, I will change the test case tomorrow

Maybe using . as the delimiter would be more intuitive?

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

3 participants