Last active
July 13, 2019 04:36
-
-
Save renatorib/7c4e3dca7458a126be380efb7ac710ed to your computer and use it in GitHub Desktop.
some js type check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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