Type improvements (#706)
* use nanobus for the emitter typings instead of `events`, which is a bit different * add typings for `cache` option
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { expectAssignable, expectType } from 'tsd'
|
||||
import Choo = require('.')
|
||||
|
||||
new Choo({})
|
||||
new Choo()
|
||||
|
||||
new Choo({ cache: 100 })
|
||||
new Choo({
|
||||
cache: new Map()
|
||||
})
|
||||
new Choo({
|
||||
cache: {
|
||||
get: (id) => null,
|
||||
set: (id, value) => expectType<any>(value)
|
||||
}
|
||||
})
|
||||
|
||||
const app = new Choo({
|
||||
history: false,
|
||||
href: true,
|
||||
})
|
||||
|
||||
app.use((state, emitter) => {
|
||||
state.title = 'choo choo'
|
||||
emitter.on(state.events.DOMCONTENTLOADED, () => {
|
||||
emitter.emit('example')
|
||||
})
|
||||
})
|
||||
|
||||
app.route('/', (state, emit) => {
|
||||
expectAssignable<object>(state.params)
|
||||
expectType<string>(state.href)
|
||||
expectType<string>(state.route)
|
||||
expectType<string>(state.title)
|
||||
emit('example')
|
||||
})
|
||||
|
||||
expectType<string>(app.toString('/'))
|
||||
|
||||
app.mount('body')
|
||||
Reference in New Issue
Block a user