Skip to content

Instantly share code, notes, and snippets.

@renatorib
Last active July 13, 2019 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renatorib/7c4e3dca7458a126be380efb7ac710ed to your computer and use it in GitHub Desktop.
Save renatorib/7c4e3dca7458a126be380efb7ac710ed to your computer and use it in GitHub Desktop.
some js type check
type ActionsBlock = {
!type: 'actions'
!elements: [
| StaticSelectElement
| UsersSelectElement
# | ConversationsSelectElement
# | ChannelsSelectElement
# | ButtonElement
# | OverflowElement
# | DatepickerElement
]
block_id: string
}
type PlainTextElement = {
!type: 'plain_text'
!text: string & range(1, 3000)
emoji: boolean
}
type Option = {
!text: PlainTextElement
description: PlainTextElement
value: string & range(1, 75)
}
type Confirm = {
confirm: PlainTextElement
deny: PlainTextElement
text: PlainTextElement
title: PlainTextElement
}
type StaticSelectElement = {
!type: 'static_select'
!options: [Option]
options_group: [{
label: PlainTextElement
options: Option
}]
action_id: string
placeholder: PlainTextElement
confirm: Confirm
initial_option: Option
}
type UsersSelectElement = {
!type: 'static_select'
action_id: string
placeholder: PlainTextElement
confirm: Confirm
initial_option: Option
}
import { validate, type } from './test.jstc'
const value = {
type: "actions",
elements: [
{
type: "users_select"
},
{
type: "static_select",
options: [
{
value: 'option-1',
text: {
type: "plain_text",
text: "Option 1"
}
},
{
value: 'option-2',
text: {
type: "plain_text",
text: "Option 2"
}
}
]
}
]
}
expect(await type('ActionsBlock').validate(value)).toBeTruthy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment