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

Alternate collision handling #14

Open
CWSpear opened this issue Aug 23, 2018 · 1 comment
Open

Alternate collision handling #14

CWSpear opened this issue Aug 23, 2018 · 1 comment

Comments

@CWSpear
Copy link

CWSpear commented Aug 23, 2018

Is there a way to handle collisions differently?

For example, we have these JSON translation files, so we don't really have the option of how they're structured, and they're all over the board. An example slice of one we've got has two different definitions for title:

{
  "history": {
    "title": {
      "header": "History",
      "sidebar": "Filter"
    }
  },
  "search": {
    "title": {
      "memberTasks": "Member Tasks",
      "tasks": "Tasks"
    }
  }
}

If you paste this on https://shakyshane.github.io/json-ts/, you'll get this output (not that it merged our title together into an interface with all of the properties as optional):

interface IRootObject {
    history: IHistory;
    search: ISearch;
}
interface IHistory {
    title: ITitle;
}
interface ITitle {
    header?: string;
    sidebar?: string;
    memberTasks?: string;
    tasks?: string;
}
interface ISearch {
    title: ITitle;
}

This has caused some issues. Is there a way we could have the output for this (perhaps with a flag) be something like:

interface IRootObject {
    history: IHistory;
    search: ISearch;
}
interface IHistory {
    title: ITitle;
}
interface ITitle {
    header: string;
    sidebar: string;
}
interface ISearch {
    title: ITitle2;
}
interface ITitle2 {
    memberTasks: string;
    tasks: string;
}

It's not even really important how you handle the naming... ITitle and ITitle2 or IHistoryTitle and ISearchTitle would both work (the latter might be easier to handle?).

@shakyShane
Copy link
Owner

shakyShane commented Feb 12, 2019

@CWSpear thanks for this, sorry I completely missed it when you first raised.

Yes, this is a known problem and something I regret - it's caught me out a few times now.

I think a better/simpler approach would be a flag like --no-merge which would produce type names that are a .join() on the elements position.

eg: in your example would be something like this, where no types are merged

interface IHistoryTitle {
    header: string;
    sidebar: string;
}

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