-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
[5.0.0] built-in .d.ts is missing some(or many) types from @types/webpack #11630
Comments
Also, |
Also, the type for generated for Source says: /** @typedef {null|undefined|RegExp|Function|string|number|boolean|bigint|undefined} CodeValuePrimitive */ (it has .d.ts says: type RecursiveArrayOrRecord =
| string
| number
| bigint
| boolean
| Function
| RegExp
| RuntimeValue
| { [index: string]: RecursiveArrayOrRecord }
| RecursiveArrayOrRecord[]; Is the .d.ts being generated with |
I miss some types from
@AviVahl maybe you should rewrite title like this?
|
Done. I've encountered the |
The |
A lot of |
I think you can send a PR for exporting more types as per your need. Types can be exposed by adding |
@snitin315 why are these types not part of the |
to add, also missing |
Yes, feel free to send a PR with fixes |
Just for information, original loader interface: interface Loader extends Function {
(this: LoaderContext, source: string | Buffer, sourceMap?: RawSourceMap): string | Buffer | void | undefined;
/**
* The order of chained loaders are always called from right to left.
* But, in some cases, loaders do not care about the results of the previous loader or the resource.
* They only care for metadata. The pitch method on the loaders is called from left to right before the loaders are called (from right to left).
* If a loader delivers a result in the pitch method the process turns around and skips the remaining loaders,
* continuing with the calls to the more left loaders. data can be passed between pitch and normal call.
*/
pitch?(remainingRequest: string, precedingRequest: string, data: any): any;
/**
* By default, the resource file is treated as utf-8 string and passed as String to the loader.
* By setting raw to true the loader is passed the raw Buffer.
* Every loader is allowed to deliver its result as String or as Buffer.
* The compiler converts them between loaders.
*/
raw?: boolean;
} I think we need improve this |
As of 4.41.23, Adding the |
|
I also found some issues with the new types.
|
Yep, feel free to send a fix |
I'm encountering that WatchOptions is not exported but has the correct type. So please add to exports. |
|
@evilebottnawi thanks that works, didn't know this was an option. |
@evilebottnawi thanks for the tip. We can push that even further, extracting the return values of functions by using export type Watching = ReturnType<Compiler["watch"]>;
export type WebpackLogger = ReturnType<Compilation["getLogger"]>; I still think that a coherent typings file should export the entire surface of names that are used to define the "top-level" types. However, these techniques mitigate the issue somewhat. |
we will focus on types in near future, anyway you can send a PR to improve this |
To be honestly, webpack don't know this stuff, because only object allowed, function/promises allowed by webpack-cli so you can use: import type { Configuration } from 'webpack';
export default (env: Record<string, any>, args: Record<string, any>): Configuration => {
return { mode: 'production' }
} Don't know why these types was added to webpack types + they are wrong. |
Any chance this can be added in the core types directly as a |
|
Is that something that should be provided from the CLI side of things or is the idea that those types are out of webpack's (or the CLI's) scope until it's given as a configuration object? |
I think |
It is not possible to supply the correct type between passed args in CLI (i.e. |
How we can detect |
Are you saying |
I don't understand your problem, |
And I don't understand why It is generally bad TS practice to use I think something like the following would make people needing this happy (but would love feedback from others, /Cc @vitoyucepi, @kavsingh, @MarkKoester): import type { Configuration } from 'webpack';
export type ConfigurationFactory<T, U> = (env: T, args: U) => Configuration; (I personally would prefer The example from the Webpack doc would become something along the lines of: import type { ConfigurationFactory } from 'webpack';
const configFactory: ConfigurationFactory<never, { mode?: Configuration['mode'] }> = (env, argv) => {
if (argv.mode === 'development') {
config.devtool = 'source-map';
}
if (argv.mode === 'production') {
//...
}
return config;
};
export default configFactory; |
I see, make sense... we need think how better to do it, maybe in future we will have more args... |
It seems clunky to put the responsibility on consumers to define the types they're concerned with, especially since the process for it is mostly just boilerplate (looking up the type from the configuration object). If webpack (CLI?) knows what properties it expects in as CLI arguments shouldn't those be exposed to consumers? Even if it's just something as simple as: type Args = { [k in keyof Configuration]: string } I'd rather make type safety the default case rather than having it rely on consumers correctly defining the configuration function type. |
So only And
Should be easy right now, also we can solve this #12294 |
@alexander-akait I've tried to implement |
@vitoyucepi Bad solution, you need add js docs types, no need to duplicate |
To be honest, it feels like the built-in types are in a much better shape now than when this issue was first opened. |
@AviVahl Let's keep open until we solve |
Hi, in one of our TS projects, we have a custom |
@harelmo feel free to send a PR |
Just to recap on the So the easiest way to get it typed now is to add types from #11630 (comment) : import type { Configuration } from 'webpack';
export default (env: Record<string, any>, args: Record<string, any>): Configuration => {
return { mode: 'production' }
} And the current plan is to create an appropriate generic in |
@OnkelTem personally I think there are 4 variants to do it
|
Hello, There has been no activity here for a long time, so I close this issue, anyway it doesn't mean we don't want to provide more types, ping me here (and I will reopen and update the issue) or create a new issue if you want more types, thank you |
@alexander-akait would you mind reopening this? |
We don't have |
Bug report
Encountered this while trying to upgrade my loader to
webpack@5
.In
webpack@4
, with@types/webpack
, I could create a fully typed loader.In
webpack@5
, there's aren't any exported types for theLoader
or theLoaderContext
What is the expected behavior?
Auto generate (?) or just include these interfaces:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6a1c6a5567fa177396fa802b2367ec34e1028eea/types/webpack/index.d.ts#L2116
Other relevant information:
webpack version: 5.0.0
Node.js version: 14.13.1
Operating System: Fedora 32
Additional tools:
The text was updated successfully, but these errors were encountered: