cycle-telegram
cycle-telegram copied to clipboard
Update type
Rewrite Update type to support
https://github.com/Microsoft/TypeScript/pull/12114
https://github.com/Microsoft/TypeScript/issues/12491
Some thoughts:
type Matcher<T> = {
[P in keyof T]: (u: Pick<T, P>) => void
}
function checkType (u: Matcher<Update>) {
}
checkType({
'callback_query': (u) => {
u.bad_type // bad
u.callback_query // ok
},
'message': (u) => {
u.callback_query // bad
u.message // ok
},
'edited_message': (u) => {
u.edited_message // ok
},
'inline_query': (u) => {
u.inline_query // ok
},
'chosen_inline_result': (u) => {
u.chosen_inline_result // ok
},
})