Skip to content
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

TS type for Entry error #11063

Closed
ebuchmann opened this issue Jun 18, 2020 · 12 comments
Closed

TS type for Entry error #11063

ebuchmann opened this issue Jun 18, 2020 · 12 comments

Comments

@ebuchmann
Copy link

ebuchmann commented Jun 18, 2020

Bug report

What is the current behavior?

Typing error with the following:

import { Configuration } from 'webpack';

const configuration = (): Configuration => {
  const webpackConfig = {
    mode: 'development' as const,
    entry: ['webpack-hot-middleware/client', path.join(__dirname, '..', 'client', 'index.jsx')],
    plugins: [
      new HtmlWebPackPlugin({
        title: config.pageTitle,
        template: path.join(__dirname, '..', 'client', 'index.html'),
        filename: path.join(__dirname, '..', 'client', 'index.html'),
      }),
      new webpack.HotModuleReplacementPlugin(),
    ],
    output: {
      filename: '[name].bundle.js',
      path: path.resolve(__dirname, '..', 'client'),
      publicPath: config.basePath,
    },
  };

  return webpackConfig;
};
  Types of property 'entry' are incompatible.
    Type 'string[]' is not assignable to type 'string | (() => string | EntryObject | [string, ...string[]] | Promise<EntryStatic>) | EntryObject | [string, ...string[]] | undefined'.
      Property '0' is missing in type 'string[]' but required in type '[string, ...string[]]'.ts(2345)

The typing for Entry:

type Entry =
	| string
	| (() => string | EntryObject | [string, ...string[]] | Promise<EntryStatic>)
	| EntryObject
	| [string, ...string[]];

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

The code works fine, the typing shouldn't be throwing an error for something that is valid. It seems the last part of the typing should just be string[], which works fine if I adjust it manually.

Other relevant information:
webpack version: webpack 5 beta 18
Node.js version: 12
Operating System: macos
Additional tools: vscode

@sokra
Copy link
Member

sokra commented Jun 24, 2020

You could try that:

-entry: ['webpack-hot-middleware/client', path.join(__dirname, '..', 'client', 'index.jsx')],
+entry: ['webpack-hot-middleware/client', path.join(__dirname, '..', 'client', 'index.jsx')] as const,

@alexander-akait
Copy link
Member

Answer above

@ebuchmann
Copy link
Author

I did try that, didn't work. For now I just have to @ts-ignore the line because it doesn't like the typing of [string, ...string[]].

@alexander-akait
Copy link
Member

/cc @sokra I think it is bug, here infromation microsoft/TypeScript#30798

@mitchell-frost
Copy link

Can I work on this issue?

@alexander-akait
Copy link
Member

Yes, PR welcome

@mitchell-frost
Copy link

How do I reproduce the bug and where are the changes supposed to be made?

@alexander-akait
Copy link
Member

Example above

@sokra
Copy link
Member

sokra commented Jul 16, 2020

We can workaround that problem omitting minLength from the Schema for generating type declarations

See webpack/tooling repo

@mitchell-frost
Copy link

I created a simple webpack project with the documentation here https://webpack.js.org/guides/getting-started/ and copied and pasted the code above. I don't understand where the code for the type entry is supposed to be. i could not reproduce the bug with npx webpack or npm run build . Is there some other process involved in reproducing it?

@moltar
Copy link

moltar commented Oct 14, 2020

Also having a similar issue.

I'm defining an entry in a variable:

const entry: Record<string, string[]> = {
  foo: ['bar', 'baz']
}

But when I supply this to configuration, get the following:

Type 'Record<string, string[]>' is not assignable to type 'Entry'.
  Type 'Record<string, string[]>' is not assignable to type 'string'.ts(2322)

types.d.ts(1790, 2): The expected type comes from property 'entry' which is declared here on type 'Configuration'

@alexander-akait
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants