{"id":17746746,"url":"https://github.com/andrekovac/typescript-minimal-example","last_synced_at":"2025-04-01T05:13:19.762Z","repository":{"id":76129277,"uuid":"448342317","full_name":"andrekovac/typescript-minimal-example","owner":"andrekovac","description":"A tiny example to demonstrate how the TypeScript compiler `tsc` compiles files to JavaScript","archived":false,"fork":false,"pushed_at":"2023-12-13T15:25:35.000Z","size":2008,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-12-13T16:40:07.525Z","etag":null,"topics":["education","workshop"],"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/andrekovac.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":"2022-01-15T17:15:34.000Z","updated_at":"2022-01-15T17:16:25.000Z","dependencies_parsed_at":"2023-12-13T16:46:14.323Z","dependency_job_id":null,"html_url":"https://github.com/andrekovac/typescript-minimal-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrekovac%2Ftypescript-minimal-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrekovac%2Ftypescript-minimal-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrekovac%2Ftypescript-minimal-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrekovac%2Ftypescript-minimal-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrekovac","download_url":"https://codeload.github.com/andrekovac/typescript-minimal-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246586036,"owners_count":20801028,"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":["education","workshop"],"created_at":"2024-10-26T08:41:50.440Z","updated_at":"2025-04-01T05:13:19.733Z","avatar_url":"https://github.com/andrekovac.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minimal TypeScript example\n\nTypeScript is a super set of JavaScript. It adds static typing to JavaScript. TypeScript is compiled to JavaScript.\n\n![TypeScript in VSCode and in the browser](./TypeScript.png)\n\n## Run\n\n1. Install the typescript dependency by running `npm install` in this folder\n2. Run `npm run build` to compile the typescript file to javascript\n3. Run `node index.js` to run the compiled application\n\n## What?\n\nThis codebase demonstrates how the TypeScript compiler `tsc` compiles `index.ts` (using modern JavaScript syntax)\n\n```ts\ntype Person = {\n  name: string;\n  age?: number;\n};\nconst person1 = {\n  name: \"Andre\",\n  age: 16,\n};\n\nconst getPersonDetails = (person: Person) =\u003e {\n  return person.age !== undefined\n    ? `${person.name}: ${person.age} years`\n    : person.name;\n};\n\nconsole.log(getPersonDetails(person1));\n```\n\ninto the following JavaScript file `index.js` (ECMAScript version 3 - published in December 2009):\n\n```js\n\"use strict\";\nvar person1 = {\n    name: \"Andre\",\n    age: 16\n};\nvar getPersonDetails = function (person) {\n    return person.age !== undefined\n        ? \"\".concat(person.name, \": \").concat(person.age, \" years\")\n        : person.name;\n};\nconsole.log(getPersonDetails(person1));\n```\n\n## Overview\n\nRunning `yarn build-and-run` combines two commands which do the following:\n\n1. `tsc --project .`: Run the TypeScript compiler `tsc` to compile `index.ts` (TypeScript) to `index.js` (JavaScript).\n2. `node index.js`: The node script `index.js` is then directly run in the command line.\n\n## Things to play around with\n\n### Change ECMAScript target version of TypeScript compiler\n\n1. In `tsconfig.json` change `\"target\": \"ES3\",` to `\"target\": \"ES6\",`\n2. Run the `build-and-run` script (i.e. `yarn build-and-run`)\n3. Which differences do you observe in `index.js`?\n\n### How does TypeScript compile an `enum` ?\n\n1. In `index.ts` add the following enum:\n\n  ```ts\n  enum Lang {\n    \"en\",\n    \"de\",\n    \"zh\",\n  }\n\n  const lang = Lang.en;\n  ```\n\n2. Run the `build` script (i.e. `yarn build`);\n3. What appeared in `index.js`?","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrekovac%2Ftypescript-minimal-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrekovac%2Ftypescript-minimal-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrekovac%2Ftypescript-minimal-example/lists"}