types/sequelize

AssociationOptionsHasOne does not have scope

Opened this issue · 1 comments

tteke commented

As the title says AssociationOptionsHasOne does not have a scope although in the Sequelize it is possible to add scole to hasone association.

I take it you're using v4 from the name; it's called HasOneOptions in v5 typings, and it looks like it's fixed in v5 beta.

If you've solved the problem, you might close the issue. If not, you can override locally using typescript's declare module. Here's an example of how I did it for similar issues:

import * as Sequelize from 'sequelize';
declare module 'sequelize' {
    interface AssociationOptionsHasOne {
        sourceKey?: string;
    }

    interface AssociationOptionsBelongsTo {
        scope?: Sequelize.AssociationScope;
    }

    interface DataTypes {
        GEOGRAPHY: any;
        CIDR: any;
        INET: any;
        MACADDR: any;
    }
}

I think it's called "declaration merging" or something, and it's limited. But when you need to add a missing property, it definitely works.