cycle-telegram icon indicating copy to clipboard operation
cycle-telegram copied to clipboard

Update type

Open goodmind opened this issue 9 years ago • 2 comments

Rewrite Update type to support https://github.com/Microsoft/TypeScript/pull/12114

goodmind avatar Nov 14 '16 04:11 goodmind

https://github.com/Microsoft/TypeScript/issues/12491

goodmind avatar Nov 27 '16 15:11 goodmind

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
  },
})

goodmind avatar Dec 02 '16 08:12 goodmind