Code Monkey home page Code Monkey logo

Comments (14)

pillowsoft avatar pillowsoft commented on May 10, 2024 1

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.

SonofNun15 avatar SonofNun15 commented on May 10, 2024

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.

jbrantly avatar jbrantly commented on May 10, 2024

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.

SonofNun15 avatar SonofNun15 commented on May 10, 2024

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.

SonofNun15 avatar SonofNun15 commented on May 10, 2024

Resolution was to wait and see what the TypeScript team does with export of type definitions for external modules.

from ts-loader.

flyon avatar flyon commented on May 10, 2024

@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.

cspotcode avatar cspotcode commented on May 10, 2024

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.

jbrantly avatar jbrantly commented on May 10, 2024

Yup, going to reopen this to track adding individual file .d.ts output so at least other tools can consume them.

from ts-loader.

flyon avatar flyon commented on May 10, 2024

Great!

from ts-loader.

jbrantly avatar jbrantly commented on May 10, 2024

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.

flyon avatar flyon commented on May 10, 2024

@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.

jbrantly avatar jbrantly commented on May 10, 2024

Apologies for the delay, this has been published in v0.8.0.

from ts-loader.

rob-bateman avatar rob-bateman commented on May 10, 2024

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.

rob-bateman avatar rob-bateman commented on May 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.