Originally published byDev.to
new stuff dropped in duckkit π¦
typed event emitter. function composition. partial application.
here's what it looks like.
before
emitter.on('win', (amount) => {
// amount is any π¬
})
emitter.emit('win', 'oops') // no error
emitter.emit('wiiin', 500) // typo. also no error.
after
const emitter = createEmitter<{
win: number
spin: void
error: { code: number; message: string }
}>()
emitter.emit('win', 500) // β
emitter.emit('win', 'oops') // β TypeScript error
emitter.emit('wiiin', 500) // β TypeScript error
emitter.emit('win') // β payload missing
define the map once. TypeScript does the rest.
pipeline β reusable composed functions
const process = pipeline(
(s: string) => s.trim(),
s => s.toUpperCase(),
s => s.split(' '),
)
process(' hello world ') // ["HELLO", "WORLD"]
process(' foo bar ') // ["FOO", "BAR"]
async steps work too β mix sync and async freely.
curry
const multiply = curry((factor: number, value: number) => value * factor)
[1, 2, 3].map(multiply(2)) // [2, 4, 6]
[1, 2, 3].map(multiply(10)) // [10, 20, 30]
npm install duckkit
do you use typed emitters? or just wing it with strings? π
πΊπΈ
More news from United StatesUnited States
NORTH AMERICA
Related News

Static Site Hosting on AWS β S3, CloudFront, ACM, and Route 53
20h ago
Selling Software in Countries PayPal Can't Reach - A Cautionary Tale of Crypto and Custom Solutions
18h ago

Construyendo la PC de Escritorio de tus SueΓ±os
19h ago
My Old MacBook Air Couldn't Handle It β So I Used Google Colab to Train an AIοΌ1
18h ago
Paying the bills in a restricted country with cryptocurrency: the lie that almost killed our digital product
10h ago