-
-
Save rbiggs/f46982d2f6e82e8c416f9af76e199d4c to your computer and use it in GitHub Desktop.
Example of compact JSDoc type definitions.
This file contains 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
/** 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