Skip to content

Instantly share code, notes, and snippets.

@rbiggs
Last active October 21, 2019 19:22
Show Gist options
  • Save rbiggs/f46982d2f6e82e8c416f9af76e199d4c to your computer and use it in GitHub Desktop.
Save rbiggs/f46982d2f6e82e8c416f9af76e199d4c to your computer and use it in GitHub Desktop.
Example of compact JSDoc type definitions.
/** Definition for item.
@typedef {{
key: number,
value: string
}} Item
*/
/** The property `items` is an array of type Item.
@typedef {{
newKey: number,
inputValue: string,
items: Item[]
}} State
*/
/** This type's methods return Message objects that are sent to the program's update method and processed by the action methods.
@typedef {{
updateInputValue:(value: string) => State,
addItem: () => State,
deleteItem: (key: number) => State,
useFetchedData: (data: State) => State
}} ActionMethods
*/
/** This is the type for the object of methods used in Msg.match of the update function to trigger the correct actions for the received message.
@typedef {{
match: (msg: Message, Object: ActionMethods) => State,
updateInputValue: (value: string) => State,
addItem: () => State,
deleteItem: (key: number) => State,
useFetchedData: (data: State) => State
}} MessageUnion
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment