Skip to content

Instantly share code, notes, and snippets.

@rbiggs
Created October 22, 2019 01:31
Show Gist options
  • Save rbiggs/a243817a7800fc45721dbbe0d0eadec4 to your computer and use it in GitHub Desktop.
Save rbiggs/a243817a7800fc45721dbbe0d0eadec4 to your computer and use it in GitHub Desktop.
TypeScript Interfaces
/** Definition for item. */
interface Item {
key: number;
value: string;
}
/** The property "items" is an array of type Item. */
interface State {
newKey: number;
inputValue: string;
items: Item[];
}
/** This type's methods return Message objects that are sent to the program's update method and processed by the action methods.*/
interface ActionMethods {
updateInputValue:(value: string) => State;
addItem: () => State;
deleteItem: (key: number) => State;
useFetchedData: (data: State) => State;
}
/** 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. */
interface MessageUnion {
match: (msg: Message, Object: ActionMethods) => State;
updateInputValue: (value: string) => State;
addItem: () => State;
deleteItem: (key: number) => State;
useFetchedData: (data: State) => State;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment