json files should be usable in .d.ts files without breaking things
See original GitHub issueSearch Terms
resolveJsonModule import definition
Suggestion
As a .json file is a static resource, it should be able to be referenced in a global.d.ts file for example without that file being automatically treated as a module. The reason for this is that a .json file may be used to simply enforce valid translation keys, and you shouldn’t need to suck the whole .json file into the transpilation process to do that.
Use Cases
Example:
import translations from "../assets/translations/en-AU.json"
type $translate = {
instant: (translationKey: keyof typeof translations) => string,
use: Function,
proposedLanguage: Function
}
The downside of the current method again is that the translations file is output in the transpilation process, which is wasteful if the file is large.
What the above code snippet is trying to achieve, should be allowed in a .d.ts file without breaking global declaration functionality.
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. new expression-level syntax)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How do you produce a .d.ts "typings" definition file from an ...
from what I can tell, tsc can compile any valid JavaScript, but if it is not valid TypeScript (compile gives warnings) then the...
Read more >Highcharts TypeScript Declarations (beta)
They can be used in production, but we can't guarantee your code from breaking with future type updates. In that case, probably small ......
Read more >TypeScript rules for Bazel - bazelbuild/rules_nodejs
The ts_project rule invokes the TypeScript compiler on one compilation unit, or "library" (generally one directory of source files). In TypeScript terms, this ......
Read more >Configuring a .d.ts rollup - API Extractor
ts rollup generation, you simply need to set dtsRollup.enabled to true in your api-extractor.json config file. By default, the rollup file will be...
Read more >rollup.js
exports , you should change the file extension to .cjs . You can also use other languages for your configuration files like TypeScript....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just ran into the same issue. Given the following directory structure:
Compiling the source code results in this structure if I don’t reference
somejsonfile.json
from source code:If I do import from
somejsonfile.json
, instead of just compiling from src to build, the structure is shifted:which results in duplication of the json file and an unnecessary
src
directory insidebuild
.Unfortunately, this means that
resolveJsonModule
is unusable for what I’m trying to do - that is reading strongly typed config data from a json file.@mhegazy Is this the kind of feedback you’re looking for?
How about another parameter. “compileJsonModule”:true|false Current code would still work and for future implementations devs would have the option to keep the strucutre.