-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Doesn't work with bundled JSON #255
Comments
It seems that the compiler team decided not to generate types for JSON files in microsoft/TypeScript#36066 (comment), so I don't think this tool should do it either as we're trying to leverage the provided API rather than building lots of add-ons on top of that. As for your suggestion with adding json files to the compilation - while it looks good to me, it's probably worth adding a flag that would be disabled by default for this feature. The reason for this is that it would require your consumers to enable resolving json in their tsconfigs which they might not want or cannot do and having this feature enabled by default might have this unintentional side-effect. |
In my case it does not require this since I am using esbuild to produce a bundle ( I think it might also be helpful to document the possibility of making a |
I meant, if a dts file would have references of json files then 1) you have to ship these json files along with your bundles in order of compilation work (but not for anything else) 2) enable
Sure. Do you have any ideas when it should be printed and what it should consist of? I'm asking because for me it would be kinda obvious but I'm too biased. |
I can try making a PR and we can see if you agree with what I write.
well yes but the resulting dts file doesn't reference the json files. If I start with {
"a" : 2,
"b": 7,
"c": [1, 2, 3]
} and import {a, b, c} from "./a.json";
const x = {a, b, c};
export {a, b, c, x}; then I get output files // a.json
var a = 2;
var b = 7;
var c = [1, 2, 3];
// b.ts
var x = { a, b, c };
export { a, b, c, x }; and // Generated by dts-bundle-generator v8.0.1
export declare const a: number;
export declare const b: number;
export declare const c: number[];
export declare const x: {
a: number;
b: number;
c: number[];
};
export {}; Neither makes any reference to |
Though now I'm looking at the code and it's not obvious where to put it. |
Bug report (or feature request?)
Source code
My project looks as follows:
a.json
b.ts
tsconfig.json
To generate the bundle
npx esbuild --bundle b.ts --format=esm > b.js
dts-bundle-generator command
I want to generate
b.d.ts
withdts-bundle-generator
. I useExpected output
Something like:
Actual output
Some solutions
Make a .json.d.ts file
If I make my own file called
a.json.d.ts
it works, but it doesn't get the types from the original json file. I looked into using MakeTypes or quicktype to generate this file but I was unable to get them to generate the correct thing directly. Also they are both pretty large dependencies.Just let .json files through
The following patch works pretty well:
I get the warning:
but it generates the bundle I wanted. There seems to be additional trouble though because if I do:
the
.d.ts
file won't mentiona
.Generate a
.d.ts
file from the jsonIt's also possible to generate a
.d.ts
file on the fly from the json as follows:I think this is the best solution. I can make a PR if you like.
The text was updated successfully, but these errors were encountered: