Quick Tip - Specific Local Module Declarations
Published ....
Last modified ....
Share this post on BlueskySee discussion on Bluesky
I've been working in a codebase lately that uses a shared module across a few different files - in my case the module is a JSON file that I'm importing and I wanted to enforce consistent types for the value when it was imported across the codebase.
As far as I can tell the recommended solution looked something like this:
import jsonObject from "./some/path/to/the/file.json";
import type { MyDesiredJSONType } from "./some-types";
let actualValue = jsonObject as MyDesiredJSONType;
It felt a bit icky to me to not only copy and paste that across the codebase, but also worry about trying to remind others contributing to the code to do the same thing when they want to import the JSON value.