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

Cannot create a typescript valid nesting group #338

Closed
tomasfrancisco opened this issue Nov 7, 2024 · 1 comment · Fixed by #342
Closed

Cannot create a typescript valid nesting group #338

tomasfrancisco opened this issue Nov 7, 2024 · 1 comment · Fixed by #342
Labels
bug Something isn't working parser @terrazzo/cli

Comments

@tomasfrancisco
Copy link
Contributor

I've been trying to find a good way to nest groups using @terrazzo/tokens-tools, but typescript (v5.6.3) seems to not be happy with it.

Reproduction @ CodeSandbox

Screenshot 2024-11-07 at 16 15 19

Here are some references I've came across:

  1. https://stackoverflow.com/questions/59896317/typescript-key-index-signature-only-for-all-properties-that-are-not-defined
  2. Need way to express hybrid types that are indexable for a subset of properties  microsoft/TypeScript#17867

One workaround that could possible be used here is the repetition of type GroupCore in the inner properties and as an isolated union element of type Group.

Before:

export type Group = GroupCore & {
    [key: string]: GroupOrToken;
};

Workaround:

export type Group = GroupCore & {
    [key: string]: GroupOrToken | GroupCore;
} | GroupCore;

Or is there something I'm missing here?

@drwpow
Copy link
Collaborator

drwpow commented Nov 8, 2024

Ah you’re right this may be an impossible intersection. I actually think we could just have GroupCore | { [key: string]: GroupOrToken | GroupCore } to simplify it, since unions in TypeScript aren’t exclusive (often times they end up working the same as intersections for this reason). But if that doesn’t work, your fix is good!

This typing is more for internal usage, but complexity like this are why typing the DTCG spec with JSONSchema is tricky!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser @terrazzo/cli
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants