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

allow importing json with resolveJsonModule "as const" #33398

Closed
5 tasks
mmkal opened this issue Sep 12, 2019 · 1 comment
Closed
5 tasks

allow importing json with resolveJsonModule "as const" #33398

mmkal opened this issue Sep 12, 2019 · 1 comment

Comments

@mmkal
Copy link

mmkal commented Sep 12, 2019

Search Terms

resolveJsonModule, const

Suggestion

Allow setting "resolveJsonModule": "const" as well as false and true.

as const is very useful, as is resolveJsonModule. I should be able to use them together.

Use Cases

I have some type helpers that can build strongly-typed dictionaries from some seed data whose schema is in another domain. We'd like to be able to use the json for things outside typescript, so would rather not put it in a .ts file. resolveJsonModule is almost what we need, but we can't import as const.

Examples

Assuming that seed data is defined like this:

const data = {
  items: [{ id: 'alice', type: 'person' }, { id: 'bob', type: 'person' }, { id: 'fido', type: 'pet' }]
} as const

const testHelper = // ...lots of type magic, taking advantage of the types in `items` being {id: "alice", type: "person"} etc., not just {id: string; type: string}

testHelper.person.alice // {id: 'alice', type: 'person'}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@AnyhowStep
Copy link
Contributor

#32063

@mmkal mmkal closed this as completed Sep 12, 2019
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