types / sequelize

The typings for https://github.com/sequelize/sequelize
63 stars 37 forks source link

AssociationOptionsHasOne does not have scope #172

Open tteke opened 5 years ago

tteke commented 5 years ago

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

billybarnum commented 5 years ago

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.