Skip to content

Commit

Permalink
Add type-tests to explicitly forbid derived units in sample target
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrHoroshih committed Sep 23, 2023
1 parent 4353c76 commit b4282b4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/types/__tests__/effector/sample/sample.test.ts
Expand Up @@ -807,3 +807,41 @@ test('from unknown to known type (should fail)', () => {
"
`)
})

describe('derived unit in target', () => {
test('should not allow derived unit in target (should fail)', () => {
const start = createEvent()
const started = start.map(() => true)
const $store = createStore(false)
const $storeMap = $store.map(() => true)

const trigger = createEvent()

sample({
clock: trigger,
target: started,
})

sample({
clock: trigger,
target: $storeMap,
})

sample({
clock: trigger,
fn: () => true,
target: [started, $store, $storeMap],
})

expect(typecheck).toMatchInlineSnapshot(`
"
Argument of type '{ clock: EventCallable<void>; target: Event<boolean>; }' is not assignable to parameter of type '{ error: \\"target should be unit or array of units\\"; got: Event<boolean>; }'.
Object literal may only specify known properties, and 'clock' does not exist in type '{ error: \\"target should be unit or array of units\\"; got: Event<boolean>; }'.
Argument of type '{ clock: EventCallable<void>; target: Store<boolean>; }' is not assignable to parameter of type '{ error: \\"target should be unit or array of units\\"; got: Store<boolean>; }'.
Object literal may only specify known properties, and 'clock' does not exist in type '{ error: \\"target should be unit or array of units\\"; got: Store<boolean>; }'.
Argument of type '{ clock: EventCallable<void>; fn: () => boolean; target: (Store<boolean> | Event<boolean>)[]; }' is not assignable to parameter of type '{ error: \\"target should be unit or array of units\\"; got: (Store<boolean> | Event<boolean>)[]; }'.
Object literal may only specify known properties, and 'clock' does not exist in type '{ error: \\"target should be unit or array of units\\"; got: (Store<boolean> | Event<boolean>)[]; }'.
"
`)
})
})

0 comments on commit b4282b4

Please sign in to comment.