diff --git a/types/redux-orm/fields.d.ts b/types/redux-orm/fields.d.ts index 300764159b..3d8e9fb63b 100644 --- a/types/redux-orm/fields.d.ts +++ b/types/redux-orm/fields.d.ts @@ -8,6 +8,7 @@ export interface AttributeOpts { export class Attribute extends Field { constructor(opts?: AttributeOpts); + ['type']: 'attr'; } export interface AttributeWithDefault extends Attribute { @@ -18,10 +19,7 @@ export interface RelationalFieldOpts { to: string; relatedName?: string; through?: string; - throughFields?: { - to: string; - from: string; - }; + throughFields?: [string, string]; as?: string; } @@ -30,14 +28,18 @@ export class RelationalField extends Field { constructor(opts: RelationalFieldOpts); } -export class OneToOne extends RelationalField {} +export class OneToOne extends RelationalField { + ['type']: 'oneToOne'; +} export class ForeignKey extends RelationalField { readonly index: true; + ['type']: 'fk'; } export class ManyToMany extends RelationalField { readonly index: false; + ['type']: 'many'; } export interface AttrCreator { diff --git a/types/redux-orm/redux-orm-tests.ts b/types/redux-orm/redux-orm-tests.ts index 80cc807633..386da42e7b 100644 --- a/types/redux-orm/redux-orm-tests.ts +++ b/types/redux-orm/redux-orm-tests.ts @@ -44,6 +44,7 @@ class Book extends Model { static options = { idAttribute: 'title' as const }; + static reducer(action: RootAction, Book: ModelType) { switch (action.type) { case 'CREATE_BOOK': @@ -380,11 +381,7 @@ const sessionFixture = () => { type TestSelector = (state: RootState) => Ref; - const selector0 = createOrmSelector( - orm, - s => s.db, - session => session.Book.first()!.ref - ) as TestSelector; + const selector0 = createOrmSelector(orm, s => s.db, session => session.Book.first()!.ref) as TestSelector; const selector1 = createOrmSelector( orm, @@ -504,3 +501,6 @@ const sessionFixture = () => { Book.create({ title: 'foo', publisher: 'error' }); // $ExpectError Book.create({ title: 'foo', publisher, coverArt: 'bar', authors: [3, author] }); // $ExpectError })(); + +// redux-orm-types#18 +(() => many({ to: 'Bar', relatedName: 'foos', through: 'FooBar', throughFields: ['foo', 'bar'] }))();