UNPKG

mini-signals

Version:
43 lines (42 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tsd_1 = require("tsd"); const mini_signals_1 = require("./mini-signals"); describe('MiniSignal Typing', () => { it('should have correct types', () => { const e1 = new mini_signals_1.MiniSignal(); const l1 = e1.add(a => { (0, tsd_1.expectType)(a); }); (0, tsd_1.expectAssignable)(l1); (0, tsd_1.expectType)(e1.dispatch('foo')); (0, tsd_1.expectType)(e1.detach(l1)); }); it('should show TS error on incorrect listeners and dispatch', () => { const e1 = new mini_signals_1.MiniSignal(); (0, tsd_1.expectError)(e1.add((a) => { })); (0, tsd_1.expectError)(e1.dispatch(5)); }); it('should show TS error on incorrect binding with different types', () => { const e1 = new mini_signals_1.MiniSignal(); const e2 = new mini_signals_1.MiniSignal(); const l1 = e1.add((tsd_1.expectType)); const l2 = e2.add((tsd_1.expectType)); (0, tsd_1.expectAssignable)(l1); (0, tsd_1.expectAssignable)(l2); (0, tsd_1.expectType)(e1.detach(l1)); (0, tsd_1.expectError)(e1.detach(l2)); (0, tsd_1.expectType)(e1.dispatch('foo')); }); it('should show ts error on incorrect branded types', () => { const e1 = new mini_signals_1.MiniSignal(); const e2 = new mini_signals_1.MiniSignal(); const l1 = e1.add((tsd_1.expectType)); const l2 = e2.add((tsd_1.expectType)); (0, tsd_1.expectAssignable)(l1); (0, tsd_1.expectAssignable)(l2); (0, tsd_1.expectType)(e1.detach(l1)); (0, tsd_1.expectError)(e1.detach(l2)); (0, tsd_1.expectType)(e1.dispatch('foo')); }); });