Hello.
i have typescript project.
it contains autogenerated from .net interfaces.
file has .d.ts extension and contains in tsconfig.json
after compile in outDir i have js, d.ts for my source but i havnt autogenerated.d.ts
Why d.ts is not included in compilation result?
I think, each d.ts files should be included in outDir according project sources tree
The .d.ts files you use are an input to the build system but not an output. It's perfectly reasonable to consume some types from a .d.ts but have your output not use those types, so there'd be no reason to distribute the input .d.ts with your build results. It sounds like you'll want a post-build step in your build tool to copy the relevant .d.ts files wherever you need them.
@danquirk , thank you for your answer! I have in serverModels.d.ts declarations of server models. In my projects i use this declarations for checking translation from client models to server models.
d.ts participates in project type checking. Imagine that project which i described is npm module, which contains api-services. In another typescript code i will import this one apiservice from package described before.
api service returns server models, described in serverModels.d.ts, but after compile d.ts has not was copyed to putput of package, and it not available. Yep, i can use grunt, gulp for copy, but i think that its compile problem. exported d.ts can relates to serverModels.d.ts, which is not in output dir, it means out tree of d.ts is not correct
@danquirk, @RyanCavanaugh, @basarat, Can you help me to solve my problem? Or maybe I should provide you repo with example?
Thank you!
The .d.ts files are considered "references" the compiler will not touch them, not move them, or recreate them. the only thing it will do, if you have a /// <reference > to an input.d.ts, the generated output will have the reference rewritten to point to the source location.
An easy way to think of the .d.ts files is that they go along with your .js files. if you are copying the .js files, you should copy the matching .d.ts.
what he said ^ .d.ts are not moved around -> by design :rose:
There are reasons why I feel this is good ... e.g. one would not want node.d.ts to be moved around ... its just an ambient ref, that any module consumer should include themselves if they need it.
Thank you!
Is there a workaround to include custom typings files? For instance I have a custom main.d.ts file with interfaces:
interface s1 {
...
}
interface s2 {
....
}
interface s3 {
...
}
I have a main file index.ts which is refered in the package.json file:
import t1=require('...');
import t2=require('..');
export{
t1,
t2
}
if I add to it tripple slash references the generated d.ts file for it will change it references to refer to the source. How can I include the custom d.ts files and still have the correct references (without manually changing the generated files and without manually dragging and dropping custom d.ts files.
Add the file in your tsconfig.json in the "include" section.
No, it is not being included. I have read the documentation and read all the responses on github and stackoverflow concerning this topic, if I specify only the d.ts file nothing gets compiled, if I specify both files (the main entry point file and the d.ts file) it compiles, but still the d.ts file is not included.
Update: Found a way around.
@vsarunov If you found a way around please publish it here for others to find.
When include does not include in the compilation, it sounds very ironic to me.
Most helpful comment
@vsarunov If you found a way around please publish it here for others to find.