From a24d647874a05ee4df3275eb6442279ffee267c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zab=C5=82ocki?= <48603138+tomasz-zablocki@users.noreply.github.com> Date: Sat, 3 Aug 2019 01:03:36 +0200 Subject: [PATCH] [@types/redux-orm] correct throughFields property on many() object parameter (#37326) fixes #37293 --- types/redux-orm/fields.d.ts | 12 +++++++----- types/redux-orm/redux-orm-tests.ts | 10 +++++----- 2 files changed, 12 insertions(+), 10 deletions(-) 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'] }))();