webpack-contrib / file-loader

File Loader
MIT License
1.86k stars 257 forks source link

Create .d.ts definition with options interface for typescript #320

Closed G-Rath closed 5 years ago

G-Rath commented 5 years ago

Documentation Is:

Please Explain in Detail...

This package uses an options object for configuration, that has a series of properties that are required to be of specific types to function correctly.

This options object is not defined in a typed manner that can be used to strongly type objects in typescript.

Your Proposal for Changes

Create an index.d.ts file with an Options interface.

This is a pretty minor issue, and mainly for ease-of-use rather than actually needed.

By having a .d.ts file with such an interface, you'd be able to more accurate in TypeScript, and in Javascript via jsdoc, like so:

/**
 * The webpack configuration settings specific to the `renderer` compiler.
 *
 * @type {webpack.Configuration}
 */
const config = {
  module: {
    rules: [
      {
        test: /\.(ico|png|jpg|svg)$/,
        use: [
          {
            loader: "file-loader",
            options: {
              outputPath: "main_window"
            }
          }
        ]
      }
    ]
  }
};

and

/** @type {FileLoaderOptions} */
const fileLoaderOptions = {
  outputPath: "main_window"
};

Given how well written the documentation is on the options, this should be pretty easy. I'm willing to give it a go myself when I have some free time.

alexander-akait commented 5 years ago

Out of scope repo, please use https://github.com/DefinitelyTyped/DefinitelyTyped for types

G-Rath commented 5 years ago

Seems strange that it's not out of scope for the json5-loader repo, but to each his own.

I'll try and make a PR somewhere when I get the time.

G-Rath commented 5 years ago

I created a PR for definitions to DT: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/38229

I'll create definitions for the other loaders once that is accepted, since they'll be pretty much the same.