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

String literals? #32

Open
Benjythebee opened this issue Jun 20, 2024 · 1 comment
Open

String literals? #32

Benjythebee opened this issue Jun 20, 2024 · 1 comment

Comments

@Benjythebee
Copy link

In the example:

const JsonToTS = require('json-to-ts')

const json = {
  cats: [
    {name: 'Kittin'},
    {name: 'Mittin'}
  ],
  favoriteNumber: 42,
  favoriteWord: 'Hello'
}

JsonToTS(json).forEach( typeInterface => {
  console.log(typeInterface)
})

I am in a situation where I would expect

interface Cat {
  name: CatLiteralString;
}

rather than string

However I can understand situations where one would want string rather than a literal...

So my thinking is maybe we could have an option allowing us to define keys that should be string literals?

for example

JsonToTS(json,{ literals: ['name'] })

which could maybe naively treat all string name properties as literals ?

Thoughts?

@2LeoCode
Copy link

+1 on this one

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