could you please let me know if, there is any existing issues on the below scenario. Else i feel this is something to do with the latest release with @types/express
@types/express: 4.17.5 package and had problems.@types/express: 4.17.0 package and find no problems.The latest version problems are as follows
A temporary solution is to import express-serve-static-core and import Request from it instead of express
I'm not familiar with the build/publish processes of DefinitelyTyped but I'm wondering how the NPM package @types/[email protected] ends up having the following in its package.json:
...
"dependencies": {
"@types/body-parser": "*",
"@types/express-serve-static-core": "*",
"@types/serve-static": "*"
}
Can anybody please explain?
Using "*" causes unexpected changes in type definitions and TypeScript compilation sometimes juste stops working after such "innocent" changes... I'd be curious to know the amount of time that was spent by all developers troubleshooting this matter since yesterday... :)
@pvoisin: i spent almost a day to figure why the existing code is failing then i came to know that there was a new release on the types happened.
@Dieumi: After i refer Request and Response from 'express-serve-static-core', i get TS2345: Argument of type 'string | Query | string[] | Query[]' is not assignable to parameter of type 'string'. ย ย Type 'Query' is not assignable to type 'string'.
After a long research on the dependencies and internal dependencies in package.json me and my friend came to conclusion that with out changing any dependency version we can restrict with resolutions section in package.json, by forcing all the libraries to use specific version while resolving, it helped us to fix the issue. Below is the code snippet from my code base.
"resolutions": {
"**/@types/express": "4.17.1",
"**/@types/express-serve-static-core": "4.16.11"
}
From the above snippet we forced any dependency and internal dependency to resolved to the specifc version.
@OliverJAsh and @RyanCavanaugh can you take a look at this?
Looks like its related to https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43764. I'm getting the same error:
error
src/middleware/contextualizers.ts:55:9 - error TS2322: Type 'string | string[] | Query | Query[]' is not assignable to type 'string'.
Type 'string[]' is not assignable to type 'string'.
55 designtype = req.query.designtype;
~~~~~~~~~~
Hacky code like this is needed to satisfy TS:
const designtype = req.query.designtype as string;
@redonkulus See the migration guide: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43434#issuecomment-607181516
@OliverJAsh why not a major version? 4.17.5 break things
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43434#issuecomment-607181516
Why didn't we bump the major version? Because the version of the types must match the version of the library. #25677 (comment)
must
why? it is just the opinion of TS member, not an axiom
So this is still broken-- the latest version of @types/express just doesn't work because it references the wrong types. Anyone going to fix that?
@clar-cmp Did you see the migration guide? If you have an issue that's not answered there, please provide a reduced test case.
Anyone going to fix that?
PRs welcome!
I'm not talking about the migration guide -- specifically the types for express provide too many generic arguments to express-serve-static-core. I don't have the bandwidth unfortunately to submit a PR but wanted to mention that this is still broken.
specifically the types for
expressprovide too many generic arguments toexpress-serve-static-core.
All of the tests pass in DefinitelyTyped. Are you sure you're using the latest versions of both types?
Output from yarn list:
โโ @types/[email protected]
โ โโ @types/node@*
โ โโ @types/[email protected]
โ โโ @types/range-parser@*
โโ @types/[email protected]
โ โโ @types/body-parser@*
โ โโ @types/express-serve-static-core@*
โ โโ @types/qs@*
โ โโ @types/serve-static@*
yarn why:
=> Found "@types/[email protected]"
info Has been hoisted to "@types/express"
info This module exists because it's specified in "devDependencies".
info Disk size without dependencies: "20KB"
info Disk size with unique dependencies: "1.78MB"
info Disk size with transitive dependencies: "3.45MB"
info Number of shared dependencies: 5
=> Found "@types/[email protected]"
info Reasons this module exists
- "@types#express" depends on it
- Hoisted from "@types#express#@types#express-serve-static-core"
- Hoisted from "@types#express#@types#serve-static#@types#express-serve-static-core"
info Disk size without dependencies: "896KB"
info Disk size with unique dependencies: "1.68MB"
info Disk size with transitive dependencies: "1.68MB"
info Number of shared dependencies: 2
If I do yarn add --dev @types/express-serve-static-core it installs the latest 4.17 on top of 4.16, but the 4.16 is still there:
=> Found "@types/[email protected]"
info Has been hoisted to "@types/express-serve-static-core"
info This module exists because it's specified in "devDependencies".
info Disk size without dependencies: "896KB"
info Disk size with unique dependencies: "1.7MB"
info Disk size with transitive dependencies: "1.7MB"
info Number of shared dependencies: 3
info
=> Found "@types/express#@types/[email protected]"
info This module exists because "@types#express" depends on it.
info Disk size without dependencies: "48KB"
info Disk size with unique dependencies: "872KB"
info Disk size with transitive dependencies: "872KB"
info Number of shared dependencies: 2
info
=> Found "@types/serve-static#@types/[email protected]"
info This module exists because "@types#express#@types#serve-static" depends on it.
info Disk size without dependencies: "48KB"
info Disk size with unique dependencies: "872KB"
info Disk size with transitive dependencies: "872KB"
info Number of shared dependencies: 2
Had to entirely delete lock file in order to get it to work. Seems that yarn does not automatically update transitive dependencies, and (correctly) assumed that the older version would work, considering how its version requirement was (incorrectly) listed as *.
Is there a reason for this? Really, if express-serve-static-core only exists for types, it should have stricter guarantees. That said, there is an ongoing yarn bug to eagerly upgrade transitive dependencies.
its version requirement was (incorrectly) listed as
*.Is there a reason for this?
I'm not really sure why that's the case.
Any update on this?
Possibly duplicated
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/47339
Closing the issue as @Oliver JAsh has pointed out the way to migrate
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43434#issuecomment-607181516
Most helpful comment
@OliverJAsh why not a major version? 4.17.5 break things