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

import { Sequelize } from 'sequelize' - Class X incorrectly implements interface Y #14566

Open
2 tasks done
Timothy-Dement opened this issue May 29, 2022 · 2 comments · Fixed by #14577
Open
2 tasks done
Labels
type: bug type: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.

Comments

@Timothy-Dement
Copy link

Timothy-Dement commented May 29, 2022

Issue Creation Checklist

Bug Description

I still seem to be having a similar problem as described in #14038 with Sequelize version 6.20.1 — which is stated to have been resolved in 6.16.0.

SSCCE

  • 📦 Please see sample.tar.gz for all relevant files.
  • ℹ️ This sample expects that a local PostgreSql service is running on localhost:5432 without username and password requirements (see brew).

📑 Expand to see main.ts package.json tsconfig.json

main.ts

import { Sequelize } from 'sequelize'

async function sample(
  database: string,
  host: string,
  password: string,
  port: number,
  username: string
) {
  try {
    const sequelize = new Sequelize({
      database,
      dialect: 'postgres',
      host,
      password,
      port,
      username
    })
    await sequelize.authenticate()
    await sequelize.close()
    return 'SUCCESS'
  } catch (error) {
    return error
  }
}

sample(
  'postgres',
  'localhost',
  '',
  5432,
  ''
).then((result) => {
  console.log(result)
})

package.json

{
  "name": "sequelize",
  "version": "0.0.0",
  "description": "",
  "main": "main.js",
  "types": "types/main.d.ts",
  "scripts": {
    "build": "npm run clean && tsc",
    "clean": "rm -rf dist/* && rm -rf types/*",
    "start": "npm run build && node dist/main.js"
  },
  "license": "ISC",
  "dependencies": {
    "pg": "^8.7.3",
    "sequelize": "^6.20.1"
  },
  "devDependencies": {
    "@types/node": "^17.0.36",
    "@types/pg": "^8.6.5",
    "@types/sequelize": "^4.28.13",
    "typescript": "^4.7.2"
  }
}

tsconfig.json

/* Reference : https://www.typescriptlang.org/tsconfig */
{
  "compilerOptions": {
    /* Emit */
    "declaration": true,                          /* https://www.typescriptlang.org/tsconfig#declaration */
    "declarationDir": "types",                    /* https://www.typescriptlang.org/tsconfig#declarationDir */
    "declarationMap": true,                       /* https://www.typescriptlang.org/tsconfig#declarationMap */
    "outDir": "dist",                             /* https://www.typescriptlang.org/tsconfig#declarationMap */
    "sourceMap": true,                            /* https://www.typescriptlang.org/tsconfig#sourceMap */

    /* Interop Constraints */
    "esModuleInterop": true,                      /* https://www.typescriptlang.org/tsconfig#esModuleInterop */
    "forceConsistentCasingInFileNames": true,     /* https://www.typescriptlang.org/tsconfig#forceConsistentCasingInFileNames */

    /* Language and Environment */
    "target": "es2022",                           /* https://www.typescriptlang.org/tsconfig#target */

    /* Modules */
    "module": "commonjs",                         /* https://www.typescriptlang.org/tsconfig#module */
    "moduleResolution": "node",                   /* https://www.typescriptlang.org/tsconfig#moduleResolution */
    "rootDir": "src",                             /* https://www.typescriptlang.org/tsconfig#rootDir */

    /* Type Checking */
    "alwaysStrict": true,                         /* https://www.typescriptlang.org/tsconfig#alwaysStrict */
    "exactOptionalPropertyTypes": true,           /* https://www.typescriptlang.org/tsconfig#exactOptionalPropertyTypes */
    "noFallthroughCasesInSwitch": true,           /* https://www.typescriptlang.org/tsconfig#noFallthroughCasesInSwitch */
    "noImplicitAny": true,                        /* https://www.typescriptlang.org/tsconfig#noImplicitAny */
    "noImplicitOverride": true,                   /* https://www.typescriptlang.org/tsconfig#noImplicitOverride */
    "noImplicitReturns": true,                    /* https://www.typescriptlang.org/tsconfig#noImplicitReturns */
    "noImplicitThis": true,                       /* https://www.typescriptlang.org/tsconfig#noImplicitThis */
    "noPropertyAccessFromIndexSignature": true,   /* https://www.typescriptlang.org/tsconfig#noPropertyAccessFromIndexSignature */
    "noUncheckedIndexedAccess": true,             /* https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess */
    "noUnusedLocals": true,                       /* https://www.typescriptlang.org/tsconfig#noUnusedLocals */
    "noUnusedParameters": true,                   /* https://www.typescriptlang.org/tsconfig#noUnusedParameters */
    "strict": true,                               /* https://www.typescriptlang.org/tsconfig#strict */
    "strictBindCallApply": true,                  /* https://www.typescriptlang.org/tsconfig#strictBindCallApply */
    "strictFunctionTypes": true,                  /* https://www.typescriptlang.org/tsconfig#strictFunctionTypes */
    "strictNullChecks": true,                     /* https://www.typescriptlang.org/tsconfig#strictNullChecks */
    "strictPropertyInitialization": true,         /* https://www.typescriptlang.org/tsconfig#strictPropertyInitialization */
    "useUnknownInCatchVariables": true,           /* https://www.typescriptlang.org/tsconfig#useUnknownInCatchVariables */
  }
}

What do you expect to happen?

npm install
npm run start
Executing (default): SELECT 1+1 AS result
SUCCESS

What is actually happening?

npm install
npm run start
node_modules/sequelize/types/errors/database/exclusion-constraint-error.d.ts:10:15 - 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'.

10 declare class ExclusionConstraintError extends DatabaseError implements ExclusionConstraintErrorOptions {
                 ~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/sequelize/types/errors/database/unknown-constraint-error.d.ts:10:15 - 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'.

10 declare class UnknownConstraintError extends DatabaseError implements UnknownConstraintErrorOptions {
                 ~~~~~~~~~~~~~~~~~~~~~~


Found 2 errors in 2 files.

Errors  Files
     1  node_modules/sequelize/types/errors/database/exclusion-constraint-error.d.ts:10
     1  node_modules/sequelize/types/errors/database/unknown-constraint-error.d.ts:10

Additional context

The following tsconfig.json option must be set to false in order for import { Sequelize } from 'sequelize' to work:

{
  "compilerOptions": {
    "exactOptionalPropertyTypes": false,  /* https://www.typescriptlang.org/tsconfig#exactOptionalPropertyTypes */
  }
}

Environment

  • Sequelize version: 6.20.1
  • Node.js version: v16.15.0
  • TypeScript version: 4.7.2
  • Database & Version: PostgreSQL 14.2
  • Connector library & Version: pg 8.7.3

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time but I don't know how to start, I would need guidance.
@ephys
Copy link
Member

ephys commented Jun 2, 2022

Reopening because it was fixed in v7, not v6

@ephys ephys reopened this Jun 2, 2022
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Jun 17, 2022
@ephys ephys added type: bug type: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. and removed stale labels Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug type: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants