From c52bd313e57d345020d549ee7ded62b1888ceff0 Mon Sep 17 00:00:00 2001 From: Cesar Napoleon Mejia Leiva Date: Tue, 26 Nov 2019 17:38:19 +0800 Subject: [PATCH] chore: completes intro --- examples/hello-ts/package.json | 6 ++- examples/hello-ts/src/index.js | 23 +++++++++++ examples/hello-ts/src/index.ts | 4 +- examples/hello-ts/tsconfig.json | 8 ++++ notes/1-basics.ts | 8 ++-- ts.code-workspace | 5 +++ tsconfig.json | 4 +- yarn.lock | 68 +++++++++++++++++++++++++++++++++ 8 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 examples/hello-ts/src/index.js create mode 100644 examples/hello-ts/tsconfig.json diff --git a/examples/hello-ts/package.json b/examples/hello-ts/package.json index b44be9e54..6d978fc5a 100644 --- a/examples/hello-ts/package.json +++ b/examples/hello-ts/package.json @@ -19,5 +19,9 @@ "build": "tsc src/index.ts --outDir lib --types node --module commonjs --target ES2017", "test": "echo 'No tests'" }, - "devDependencies": {} + "devDependencies": {}, + "dependencies": { + "eslint": "^6.7.1", + "global": "^4.4.0" + } } diff --git a/examples/hello-ts/src/index.js b/examples/hello-ts/src/index.js new file mode 100644 index 000000000..a40e7d47e --- /dev/null +++ b/examples/hello-ts/src/index.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Create a promise that resolves after some time + * @param n number of milliseconds before promise resolves + */ +function timeout(n) { + return new Promise(res => setTimeout(res, n)); +} +/** + * Add two numbers + * @param a first number + * @param b second number + */ +async function addNumbers(a, b) { + await timeout(500); + return a + b; +} +exports.addNumbers = addNumbers; +//== Run the program ==// +(async () => { + console.log(await addNumbers(3, 4)); +})(); diff --git a/examples/hello-ts/src/index.ts b/examples/hello-ts/src/index.ts index 00eafca2d..ba673c72b 100644 --- a/examples/hello-ts/src/index.ts +++ b/examples/hello-ts/src/index.ts @@ -7,9 +7,9 @@ function timeout(n: number) { } /** - * Add three numbers + * Add two numbers * @param a first number - * @param b second + * @param b second number */ export async function addNumbers(a: number, b: number) { await timeout(500); diff --git a/examples/hello-ts/tsconfig.json b/examples/hello-ts/tsconfig.json new file mode 100644 index 000000000..ef43dbdc5 --- /dev/null +++ b/examples/hello-ts/tsconfig.json @@ -0,0 +1,8 @@ +{ + "include": ["src"], + "compilerOptions": { + "target": "esnext", + "module": "commonjs", + "outDir": "lib" + } +} \ No newline at end of file diff --git a/notes/1-basics.ts b/notes/1-basics.ts index c963b7a66..f7c31ad55 100644 --- a/notes/1-basics.ts +++ b/notes/1-basics.ts @@ -3,22 +3,22 @@ /** * (1) x is a string, b/c we’ve initialized it */ -// let x = "hello world"; +let x = "hello world"; /** * (2) reassignment is fine */ -// x = "hello mars"; +x = "hello mars"; /** * (3) but if we try to change type */ -// x = 42; // 🚨 ERROR +x = "42"; // 🚨 ERROR /** * (4) let's look at const. The type is literally 'hello world' */ -// const y = "hello world"; +const y = 42; /** * This is called a 'string literal type'. y can never be reassigned since it's a const, diff --git a/ts.code-workspace b/ts.code-workspace index c7b055d27..1bfd0140b 100644 --- a/ts.code-workspace +++ b/ts.code-workspace @@ -68,6 +68,11 @@ "code-runner.executorMap": { "javascript": "node", "typescript": "node_modules/.bin/ts-node" + }, + "workbench.colorCustomizations": { + "activityBar.background": "#4F1F08", + "titleBar.activeBackground": "#6E2C0B", + "titleBar.activeForeground": "#FEF9F7" } }, "extensions": { diff --git a/tsconfig.json b/tsconfig.json index 9442f6792..6eab21f11 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "strictFunctionTypes": true, "strictBindCallApply": true, "noUnusedLocals": false, - "noUnusedParameters": false + "noUnusedParameters": false, }, "include": ["examples/*/src", "challenges/*/src", "notes"] -} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 39e8781a7..736c898d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2640,6 +2640,11 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" +dom-walk@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018" + integrity sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg= + dot-prop@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-3.0.0.tgz#1b708af094a49c9a0e7dbcad790aba539dac1177" @@ -2897,6 +2902,49 @@ eslint@6.7.0: text-table "^0.2.0" v8-compile-cache "^2.0.3" +eslint@^6.7.1: + version "6.7.1" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.7.1.tgz#269ccccec3ef60ab32358a44d147ac209154b919" + integrity sha512-UWzBS79pNcsDSxgxbdjkmzn/B6BhsXMfUaOHnNwyE8nD+Q6pyT96ow2MccVayUTV4yMid4qLhMiQaywctRkBLA== + dependencies: + "@babel/code-frame" "^7.0.0" + ajv "^6.10.0" + chalk "^2.1.0" + cross-spawn "^6.0.5" + debug "^4.0.1" + doctrine "^3.0.0" + eslint-scope "^5.0.0" + eslint-utils "^1.4.3" + eslint-visitor-keys "^1.1.0" + espree "^6.1.2" + esquery "^1.0.1" + esutils "^2.0.2" + file-entry-cache "^5.0.1" + functional-red-black-tree "^1.0.1" + glob-parent "^5.0.0" + globals "^12.1.0" + ignore "^4.0.6" + import-fresh "^3.0.0" + imurmurhash "^0.1.4" + inquirer "^7.0.0" + is-glob "^4.0.0" + js-yaml "^3.13.1" + json-stable-stringify-without-jsonify "^1.0.1" + levn "^0.3.0" + lodash "^4.17.14" + minimatch "^3.0.4" + mkdirp "^0.5.1" + natural-compare "^1.4.0" + optionator "^0.8.3" + progress "^2.0.0" + regexpp "^2.0.1" + semver "^6.1.2" + strip-ansi "^5.2.0" + strip-json-comments "^3.0.1" + table "^5.2.3" + text-table "^0.2.0" + v8-compile-cache "^2.0.3" + espree@^6.1.2: version "6.1.2" resolved "https://registry.yarnpkg.com/espree/-/espree-6.1.2.tgz#6c272650932b4f91c3714e5e7b5f5e2ecf47262d" @@ -3560,6 +3608,14 @@ global-dirs@^0.1.0, global-dirs@^0.1.1: dependencies: ini "^1.3.4" +global@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/global/-/global-4.4.0.tgz#3e7b105179006a323ed71aafca3e9c57a5cc6406" + integrity sha512-wv/LAoHdRE3BeTGz53FAamhGlPLhlssK45usmGFThIi4XqnBmjKQ16u+RNbP7WvigRZDxUsM0J3gcQ5yicaL0w== + dependencies: + min-document "^2.19.0" + process "^0.11.10" + globals@^12.1.0: version "12.3.0" resolved "https://registry.yarnpkg.com/globals/-/globals-12.3.0.tgz#1e564ee5c4dded2ab098b0f88f24702a3c56be13" @@ -5088,6 +5144,13 @@ mimic-fn@^2.0.0, mimic-fn@^2.1.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== +min-document@^2.19.0: + version "2.19.0" + resolved "https://registry.yarnpkg.com/min-document/-/min-document-2.19.0.tgz#7bd282e3f5842ed295bb748cdd9f1ffa2c824685" + integrity sha1-e9KC4/WELtKVu3SM3Z8f+iyCRoU= + dependencies: + dom-walk "^0.1.0" + minimatch@3.0.4, minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" @@ -6212,6 +6275,11 @@ process-nextick-args@~2.0.0: resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== +process@^0.11.10: + version "0.11.10" + resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" + integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI= + progress@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"