Created
August 6, 2024 06:47
-
-
Save BiosBoy/8d1b1d2fcec6d92e6ac98e56b63ed60a to your computer and use it in GitHub Desktop.
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
| enum Direction { | |
| North, | |
| East, | |
| South, | |
| West | |
| } | |
| let myDirection: Direction = Direction.North; | |
| console.log(myDirection); // Output: 0 | |
| enum Status { | |
| Active = "ACTIVE", | |
| Inactive = "INACTIVE", | |
| Pending = "PENDING" | |
| } | |
| let myStatus: Status = Status.Active; | |
| console.log(myStatus); // Output: ACTIVE | |
| enum TaskState { | |
| Todo = "TODO", | |
| InProgress = "IN_PROGRESS", | |
| Done = "DONE" | |
| } | |
| interface Task { | |
| id: number; | |
| name: string; | |
| state: TaskState; | |
| } | |
| let tasks: Task[] = [ | |
| { id: 1, name: "Write article", state: TaskState.InProgress }, | |
| { id: 2, name: "Review PR", state: TaskState.Todo }, | |
| { id: 3, name: "Team meeting", state: TaskState.Done } | |
| ]; | |
| enum ResponseStatus { | |
| Success = "SUCCESS", | |
| Error = "ERROR" | |
| } | |
| interface ApiResponse { | |
| status: ResponseStatus; | |
| message: string; | |
| } | |
| function handleResponse(response: ApiResponse) { | |
| switch (response.status) { | |
| case ResponseStatus.Success: | |
| console.log("Request was successful!"); | |
| break; | |
| case ResponseStatus.Error: | |
| console.error("There was an error:", response.message); | |
| break; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment