Skip to content

Typed JSON importsΒ #60037

Closed
Closed
@sdegutis

Description

@sdegutis

πŸ” Search Terms

json import module type

βœ… Viability Checklist

⭐ Suggestion

Allow specifying the type of dynamically created and imported JSON files with .d.ts files.

πŸ“ƒ Motivating Example

import icons from '/icons.json' with { type: 'json' };

This is a type error when /icons.json doesn't exist statically. There's no way to give it a type currently.

πŸ’» Use Cases

  1. What do you want to use this for?

Give /icons.json a type when imported though it's dynamically generated.

  1. What shortcomings exist with current approaches?

/icons.json doesn't have a type, and is a type error.

  1. What workarounds are you using in the meantime?

Using fetch with a then-generic-type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions