Skip to content

Instantly share code, notes, and snippets.

@danprince
Last active May 27, 2020 21:33
Show Gist options
  • Save danprince/6dd8566e22c6a82a29cb57f195c2ff0e to your computer and use it in GitHub Desktop.
Save danprince/6dd8566e22c6a82a29cb57f195c2ff0e to your computer and use it in GitHub Desktop.
Types/Sequelize Scope Repro

Reproducing types/sequelize/120. Run npm test to see compile errors.

index.ts(14,3): error TS2345: Argument of type '{ scopes: { human: { slack_id: { $ne: string; }; }; }; }' is not assignable to parameter of type 'InitOptions'.
  Property 'sequelize' is missing in type '{ scopes: { human: { slack_id: { $ne: string; }; }; }; }'.
index.ts(25,1): error TS2684: The 'this' context of type 'typeof Model' is not assignable to method's 'this' of type '(new () => Model) & typeof Model'.
  Type 'typeof Model' is not assignable to type 'new () => Model'.
    Cannot assign an abstract constructor type to a non-abstract constructor type.
import { Model, DataTypes } from "sequelize";
class User extends Model {
id: number;
created_at: Date;
updated_at: Date;
slack_id: string;
}
User.init(
{
slack_id: DataTypes.STRING
},
{
scopes: {
human: {
slack_id: { $ne: "USLACKBOT" }
}
}
}
);
let HumanUsers = User.scope("human");
HumanUsers.findById(4).then(user => {
if (user) {
console.log(user);
}
});
{
"scripts": {
"test": "tsc"
},
"dependencies": {
"@types/sequelize": "types/sequelize#660ddda",
"sequelize": "4.2.0",
"typescript": "2.4.2"
}
}
{
"compilerOptions": {
"target": "es2017"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment