-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
json files should be usable in .d.ts files without breaking things #24744
Comments
Unfortunately I've the very same issue on a project of mine where the json is imported into the "dist" folder breaking seveal things. |
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
If I do import from
which results in duplication of the json file and an unnecessary Unfortunately, this means that @mhegazy Is this the kind of feedback you're looking for? |
I just ran into this same issue myself. As @AlCalzone shows above, when importing a json and using the
It's quite strange because it issues an error, but then carries on with the build, implicitly setting I've attempted to skirt this issue by setting the
or by
or by both
but in all cases, I get the As of now, I've had to revert to using |
I actually only want to use a type that is derived from the contents of the json file, not the contents of the file itself. I feel there should be a way to rely on json files without including them in the build output. |
Over the weekend I ran into another issue, where having type checking based on the types from a json config file would have saved me some headaches. A numeric variable was incorrectly set as a |
This works for me, but I refuse to believe this feature is working as intended. Edit: checking out a repo with symlinks is problematic on windows though...
|
How about another parameter. "compileJsonModule":true|false |
Have simillar issue: import program from 'commander'
import { version } from '../package.json'
program
.version(version)
.parse(process.argv)
|
I find it interesting that even if TS2732 error occurs, the tsc compiler just continues. Surely there must be a way to make it not bother compiling the JSON file, so that we can reference things outside the |
Search 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:
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:
The text was updated successfully, but these errors were encountered: