sindresorhus / type-fest

A collection of essential TypeScript types
Creative Commons Zero v1.0 Universal
14.02k stars 532 forks source link

Proposal | Add an Paths type thats returns all valid paths to JSON like values #323

Open joseDaKing opened 2 years ago

joseDaKing commented 2 years ago

I am currently building my own abstraction on top of styled-components and I won't my theme getters to be strictly typed.

type Theme = {
  colors: {
    blue: [
      string,
      string, 
    ],
    red: {
      a: string;
      b: string;
    }
    orange: Array<string>;
  },
}

type Paths<Theme, "/"> = ...;
// Type will be these values
// "colors/blue/0"
// "colors/blue/1"
// "colors/red/a"
// "colors/red/b"
// `colors/orange/${number}`

Perhaps the Paths type could return instead tuples that resample the path and we could have a Join type to join the tuples with a delimiter.

Upvote & Fund

Fund with Polar

sindresorhus commented 1 year ago

Duplicate of #432

sindresorhus commented 1 year ago

I'm keeping this issue open as a separator option can be added later on.

fregante commented 4 weeks ago

Fixed in https://github.com/sindresorhus/type-fest/pull/741?