Skip to content

Declare a type with a JSON file instead of an interface #23898

Closed
@ORESoftware

Description

@ORESoftware

Search Terms

typescript json interface file

Suggestion

I have this question on SO:
https://stackoverflow.com/questions/50181254/static-typing-with-json-and-typescript?noredirect=1#comment87380729_50181254

Why can't we declare a TS type based on a .json file? Something like this:

export type MyInterface = typeof 'path/to/json/file.json'

it seems like a no-brainer to me, but maybe I am stupid.

Use Cases

Keep things DRY. Use JSON files as interfaces.

Examples

Done did.

Checklist

My suggestion meets these guidelines:
[x] This wouldn't be a breaking change in existing TypeScript / JavaScript code
[x] This wouldn't change the runtime behavior of existing JavaScript code
[x] This could be implemented without emitting different JS based on the types of the expressions
[x] This isn't a runtime feature (e.g. new expression-level syntax)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions