Comments (14)
I also tried it and it did generate the definitions 👍. However, I ran into one issue and wanted to see if you had thoughts on a fix. I like to create files that just have interface definitions that are shared and then import those definitions into the files that need the types. Alas, when I do that, no type definitions are generated for those files. Typescript correctly generates them using "declaration": true, but ts-loader is not. Perhaps ts-loader somehow sees no code is in the file and then does not generate the definition?
Here's an example of a type only file:
export interface IImageInfo {
src: string;
thumbnail?: string;
description?: string;
originalClass?: string;
thumbnailClass?: string;
srcset?: Array<any>;
caption?: string;
}
Thoughts? Thanks!
from ts-loader.
By the way, ts-loader is awesome. I am so happy with webpack and ts-loader right now. This is the closest we have come to finally resolving our TS library issues! Thanks for all of your work! 😄
from ts-loader.
This is related to #45. Basically it probably wouldn't be crazy hard to support --declaration
like tsc
does where each input file gets an associated declaration file. But where things get hard is with having a single declaration file for a multiple modules. I'm not sure that is in-scope right now. I think it would be best to somehow combine with another tool that already does that or wait until TypeScript gets native support for it.
I'm open to exploring the simple case, but does that actually solve your problem?
Also, thank you for the kind words 😁
from ts-loader.
I totally understand. Combining multiple external modules into a single file (module) is kind of a hairy problem no matter how you cut it. I agree, let's see how the TS team handles it first. I think this will ultimately only have value if we intended to code split and deploy the library dynamically to the client. At this point we'll probably be bundling it with the client (using webpack / ts-loader), so this won't be an issue.
from ts-loader.
Resolution was to wait and see what the TypeScript team does with export of type definitions for external modules.
from ts-loader.
@jbrantly I think supporting --declaration for now would be nice. At least then we can generate single .d.ts files, which with other modules can be combined into one. That would solve my use-case for now at least.
from ts-loader.
I would like this as well. If I can just get access to the .d.ts EmitOutput from within a loader, I can output the .d.ts files myself. Simple loaders and plugins are so easy to write, I don't mind putting a few lines of code together, and you can still wait to implement proper .d.ts bundling.
from ts-loader.
Yup, going to reopen this to track adding individual file .d.ts output so at least other tools can consume them.
from ts-loader.
Great!
from ts-loader.
This functionality has been merged to master. Please try it out and let me know how it works out.
@cspotcode Just for fun I tried your scenario of accessing the .d.ts files from another loader. Unfortunately I was not successful. It seems that when a loader adds extra files to the output those files are not made available to other loaders. (if you dig deeper and figure out a way to do this I'd love to hear about it)
from ts-loader.
@jbrantly tnx! I downloaded the master branch and succesfully got separate .d.ts output files. Could you publish this to npm?
I played around a while with the different options of combining declaration files (like dts-generator), but ended up writing my own small WebpackPlugin in typescript because I want to combine the files in a certain way. It's defenitly not usable as-is for others, but if anyone wants to see how to do that check the npm library dacore-webpack-declarations
Other usefull information in this context: Typescript 1.8 will support generating one single declaration file for certain types of modules. The combination of compiler options outFile
and declarations
for AMD and system modules will generate a single output file with a single declaration file. You can already try it out with npm typescript@next
from ts-loader.
Apologies for the delay, this has been published in v0.8.0.
from ts-loader.
I'm also trying to generate definitions files for interfaces from ts-loader, but ran into the same problem. Had a look at the declaration-bundler-webpack-plugin by @flyon but don't see any interface files coming from the compiler 'emit' callback. Any suggestions?
from ts-loader.
created issue (#174) and pull request (#175) for resolving missing d.ts files for interface objects referenced by @pillowsoft
from ts-loader.
Related Issues (20)
- node8.11.1 reported an error, reported incompatibility
- Updating to [email protected] results in TS2502: 'AbortController' is referenced directly or indirectly in its own type annotation when used with @types/[email protected] HOT 1
- [deps] Check for breaking changes in dependency updates
- Add support for using keyword (TypeScript 5.2) HOT 7
- ts-loader inconsistent with ts compiler
- CVE-2023-28154 - Upgrade WebPack to 5.76.0 HOT 2
- ts-loader fails on stage 3 decorators: Unexpected character '@' HOT 1
- projectReferences does not build with the specified tsconfig
- After upgrading from 8.4.0 to 9.4.4, startup of a nodejs/electron app doubled HOT 3
- ts-loader can't load Typescript with any version > 5.0.4 HOT 4
- Dynamic imports with a dynamic expression are not chunked/loaded correctly HOT 1
- Is there a way to hide private method after build?
- Error when upgrading ts-loader HOT 8
- Safari shows "An error occurred trying to load the resource." when loading ts breakpoint
- Add native support for tsconfig `compilerOptions.paths`
- The 'files' list in config file 'tsconfig.json' is empty. HOT 2
- Loading custom file leads to TS2307 (Cannot find module) HOT 4
- ts-loader forces 'isolatedModules' enabled when transpileOnly: true
- Question: generate `d.ts` files for each entry
- How to silent any error from ts-loader? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-loader.