Skip to content

Commit

Permalink
Add test for attach generic factories support
Browse files Browse the repository at this point in the history
This commit should fail
  • Loading branch information
zerobias committed May 23, 2024
1 parent dc16813 commit 2e5c2d0
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/types/__tests__/effector/attach.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-unused-vars */
import {createStore, createEffect, attach, Effect} from 'effector'
import {createStore, createEffect, attach, sample, Effect} from 'effector'

const typecheck = '{global}'

Expand Down Expand Up @@ -34,6 +34,30 @@ describe('explicit generics', () => {
})
})

test('factories with generics support', () => {
function createModel<T>() {
const $data = createStore<T | null>(null)

const loadFx = attach({
source: {
/* Assume we use some $api with external API we don't control */
},
effect() {
const result: any = /* API returns `any` */ null

return result as T /* explicit cast, becase we know result is T */
},
})

sample({clock: loadFx.doneData, target: $data})
}
expect(typecheck).toMatchInlineSnapshot(`
"
no errors
"
`)
})

describe('with source', () => {
test('with single store (should pass)', () => {
const foo = createStore<string>('foo')
Expand Down

0 comments on commit 2e5c2d0

Please sign in to comment.