{"id":21654915,"url":"https://github.com/avijeetpandey/ts-essentials","last_synced_at":"2025-03-20T04:43:00.022Z","repository":{"id":203738972,"uuid":"710296016","full_name":"avijeetpandey/ts-essentials","owner":"avijeetpandey","description":"A repo to learn TS and implement","archived":false,"fork":false,"pushed_at":"2023-10-26T16:45:06.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-25T06:25:26.838Z","etag":null,"topics":["essentials","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avijeetpandey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-26T12:15:22.000Z","updated_at":"2023-11-12T15:22:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"3cef7adf-f4b3-4ce7-a63e-3acb5d82330e","html_url":"https://github.com/avijeetpandey/ts-essentials","commit_stats":null,"previous_names":["avijeetpandey/ts-essentials"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avijeetpandey%2Fts-essentials","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avijeetpandey%2Fts-essentials/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avijeetpandey%2Fts-essentials/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avijeetpandey%2Fts-essentials/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avijeetpandey","download_url":"https://codeload.github.com/avijeetpandey/ts-essentials/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244554121,"owners_count":20471173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["essentials","typescript"],"created_at":"2024-11-25T08:29:22.163Z","updated_at":"2025-03-20T04:43:00.003Z","avatar_url":"https://github.com/avijeetpandey.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Notes for the course\n\n### Defining variables with types using typescript\n\n```ts\nconst name: string = \"name\";\nconst isUser: boolean = true;\n```\n\n### Declaring or grouping types\n\n```ts\n// first way of grouping types\nlet user: {\n  name: string;\n  age: number;\n  isAdmin: boolean;\n  id: string | number;\n  hobbies: Array\u003cstring\u003e;\n  roles: string[]; // another way of defining array types\n  cellNumbers: number[];\n};\n```\n\n```ts\nlet user: {\n  name: string;\n  age: number;\n  isAdmin: boolean;\n  id: string | number;\n} = {\n  name: \"A\",\n  age: 32,\n  isAdmin: true,\n  id: 232\n};\n```\n\n### Making functions with typed parameters and return types\n\n```ts\n// function with typed parameters and return value\nfunction add(a: number, b: number): number {\n  return a + b;\n}\n\n// function type that returns nothing\nfunction addNothing(): void {\n  console.log(\"Returns nothing\");\n}\n\n// custom types or type alias using typescript\ntype CalculateCallback = (a: number, b: number) =\u003e number;\n\n// types for function with having function as a parameter\nfunction calculate(\n  a: number,\n  b: number,\n  calcFunc: (a: number, b: number) =\u003e number\n) {\n  // calling function inside\n  calcFunc(a, b);\n}\n\n// types for function with having function as a parameter\nfunction calculateWithTypeForCallback(\n  a: number,\n  b: number,\n  calcFunc: CalculateCallback\n) {\n  // calling function inside\n  calcFunc(a, b);\n}\n```\n\n### Using generics in typescript\n\n```ts\n// using generics in the code\ntype DataStorage\u003cT\u003e = {\n  storage: T[];\n  add: (data: T) =\u003e void;\n};\n\nconst dataStorage: DataStorage\u003cstring\u003e = {\n  storage: [],\n  add(data) {\n    this.storage.push(data);\n  }\n};\n\n// using generics with functions\nfunction merge\u003cT, U\u003e(a: T, b: U) {\n  return {\n    ...a,\n    ...b\n  };\n}\n```\n\n### Creating Interfaces\n\n```ts\ninterface Credentials {\n  email: string;\n  password: string;\n}\n\nconst creds: Credentials = {\n  email: \"test@abc.com\",\n  password: \"test\"\n};\n\n// An interface can be adhered to a class so that it implements all the specified properties\n// Interfaces are mostly used while creating objects\nclass AuthCredentials implements Credentials {\n  email: string;\n  password: string;\n\n  constructor() {\n    this.email = \"hello@g.cc\";\n    this.password = \"test@123\";\n  }\n}\n```\n\n### Interface union\n\n```ts\n// the same can be achieved using union as well\ninterface IUser {\n  name: string;\n  id: number | string;\n  hobbies: Array\u003cstring\u003e;\n}\n\ninterface IDashBoardUser {\n  roles: Array\u003cstring\u003e;\n}\n\n// union using interfaces\ninterface IAdminUser extends IUser, IDashBoardUser {}\n```\n\n### Types union\n\n```ts\n// union of two types\ntype Admin = {\n  permissions: string[];\n};\n\ntype AppUser = {\n  userName: string;\n};\n\ntype AppAdmin = Admin \u0026 AppUser; // union of two types\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favijeetpandey%2Fts-essentials","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favijeetpandey%2Fts-essentials","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favijeetpandey%2Fts-essentials/lists"}