Repository navigation
Description
Issue Creation Checklist
- I have read the contribution guidelines
Bug Description
Typescript builds are failing on projects using sequelize when the typescript project has certain strict typechecking options enabled in its tsconfig.json file.
The root cause is the changes to the types/index.d.ts file introduced in PR #14002 (though there are other similar errors in the index.d.ts file that likely need to be addressed as well).
Additional info:
3f75880
5e93243
This change uses ../ imports to reference files for their types, but since the index.d.ts file ends up top-level in the dist folder during a build, this effectively causes the build output to refer to <module root>/dist/../lib/errors (for example), which resolves to <module root>/lib/errors. This causes unbuilt ts files to be referenced, ultimately resulting in downstream projects failing their tsc builds when settings such as the following are set in their tsconfig.json:
"noImplicitOverride": true,
"strictNullChecks": true,
"exactOptionalPropertyTypes": true,When all type checking guards available in the tsconfig.json file are turned on, here is the exhaustive list of errors that occur after importing the module into a downstream project:
node_modules/sequelize/lib/errors/aggregate-error.ts:18:3 - error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'BaseError'.
18 toString(): string {
~~~~~~~~
node_modules/sequelize/lib/errors/database/exclusion-constraint-error.ts:12:7 - error TS2420: Class 'ExclusionConstraintError' incorrectly implements interface 'ExclusionConstraintErrorOptions'.
Types of property 'constraint' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
12 class ExclusionConstraintError extends DatabaseError implements ExclusionConstraintErrorOptions {
~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/sequelize/lib/errors/database/exclusion-constraint-error.ts:23:27 - error TS2379: Argument of type '{ stack: string | undefined; }' is not assignable to parameter of type 'ErrorOptions' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'stack' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
23 super(options.parent, { stack: options.stack });
~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/sequelize/lib/errors/database/foreign-key-constraint-error.ts:32:27 - error TS2379: Argument of type '{ stack: string | undefined; }' is not assignable to parameter of type 'ErrorOptions' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'stack' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
32 super(options.parent, { stack: options.stack });
~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/sequelize/lib/errors/database/unknown-constraint-error.ts:12:7 - error TS2420: Class 'UnknownConstraintError' incorrectly implements interface 'UnknownConstraintErrorOptions'.
Types of property 'constraint' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
12 class UnknownConstraintError extends DatabaseError implements UnknownConstraintErrorOptions {
~~~~~~~~~~~~~~~~~~~~~~
node_modules/sequelize/lib/errors/database/unknown-constraint-error.ts:23:27 - error TS2379: Argument of type '{ stack: string | undefined; }' is not assignable to parameter of type 'ErrorOptions' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'stack' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
23 super(options.parent, { stack: options.stack });
~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/sequelize/lib/errors/validation-error.ts:224:42 - error TS2532: Object is possibly 'undefined'.
224 } else if (this.errors.length > 0 && this.errors[0].message) {
~~~~~~~~~~~~~~
node_modules/sequelize/lib/errors/validation/unique-constraint-error.ts:31:44 - error TS2379: Argument of type '{ stack: string | undefined; }' is not assignable to parameter of type 'ErrorOptions' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'stack' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
31 super(options.message, options.errors, { stack: options.stack });
~~~~~~~~~~~~~~~~~~~~~~~~
Found 8 errors.
I suspect the type definitions need to be updated to not refer to any files outside of the types source folder.
I can confirm locally that by adjusting these ../ entries to instead be ./ in the dist folder resolves the issues, but I am not knowledgable to know if this translates well to the source files themselves. It looks like it wouldn't work without some additional type files in the types directory.
To recreate yourself:
- create a new node project
- install typescript
- run
npx tsc --init - modify the tsconfig.json file to include stricter type checking as per the above
- create a basic index.ts file with the following content:
import { Sequelize } from 'sequelize' console.log(Sequelize);
- run
npx tsc && node src/index.js
Environment
- Sequelize version: 6.15.0
- Node.js version: 16.13.2
- If TypeScript related: 4.5.5
Bug Report Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, but only if guidance for the ideal solution were provided and if I would not have to go through the extensive setup instructions for running unit tests in the contribution guide, since this issue is not related to actual functionality and is instead a build/packaging issue.
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Activity
[-]regression: sequelize types import files outside of 'dist' dir, causing downstream tsc issues[/-][+]sequelize types import files outside of 'dist' dir, causing downstream tsc issues[/+]WikiRik commentedon Feb 1, 2022
I'm assigning @ephys to this since they have been working on this. About the setup for testing, I think running
yarn test-typings(ornpm run test-typings) would be good enough for this.Either way, thanks for reporting this and the extensive description. I think that together we can provide a good solution to this
jharvey10 commentedon Feb 1, 2022
Okay cool. I'm definitely happy to help out in any way that I can. I can reliably reproduce it in my local environment, which is great for testing. I just don't want to step on anyone's toes because it does look like there's some work being done to prevent type duplication across the project. I'll see if I can clone the repo and get those test-typing tests running in the mean time.
ephys commentedon Feb 1, 2022
This is more issues arrising due to workaround to repair issues with the initial TS migrations :/
I think we could solve this by merging the
types&libfolders. We then copy .d.ts files to dist & emit typedefs for ts files.And then we npmignore /lib & /types
But if we do that we cause issues for users that import directly from /types (they should not do that but I'm sure some do). But that's less important than having the "proper" usage be broken.
WikiRik commentedon Feb 1, 2022
Other, more radical, option; if this is causing all these issues maybe we should revert the initial TS things for v6? With the changes we've done after it would cause quite some conflicts but it would solve this
ephys commentedon Feb 2, 2022
We could transpiles .ts files in /lib to js & copy the emitted typings to /types in the v6 branch. With some manual fixing
hardzeichyksiarhei commentedon Feb 4, 2022
Hi! Same problem, project doesn't compile in strict mode.

ephys commentedon Feb 4, 2022
We'll have a fix soon, I'm merging our existing TS PRs first before changing our build process. Only one left.
hardzeichyksiarhei commentedon Feb 4, 2022
Thanks!:)
JanFellner commentedon Feb 7, 2022
soon === undefined in typescript 😎 you have a rough timeline for it :)
(otherwise just fixing the typseript issues would heal the pain)
github-actions commentedon Feb 8, 2022
🎉 This issue has been resolved in version 6.16.0 🎉
The release is available on:
Your semantic-release bot 📦🚀