From 119422777a6e6b423caae1086f1f0c131b82b7ed Mon Sep 17 00:00:00 2001 From: Frank Pereira Date: Mon, 25 Nov 2024 17:15:40 +0100 Subject: [PATCH] change modules to ES6; add index.html with type module #1 --- stuff/ts/index.html | 14 ++++++++++++++ stuff/ts/package.json | 1 + stuff/ts/src/classesExample1.ts | 2 +- stuff/ts/src/index.ts | 4 ++++ stuff/ts/src/validate.ts | 6 +++++- stuff/ts/tsconfig.json | 6 +++--- 6 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 stuff/ts/index.html diff --git a/stuff/ts/index.html b/stuff/ts/index.html new file mode 100644 index 0000000..d1e69bc --- /dev/null +++ b/stuff/ts/index.html @@ -0,0 +1,14 @@ + + + + + + + Modules + + + + + + + diff --git a/stuff/ts/package.json b/stuff/ts/package.json index 946fa5a..fea4257 100644 --- a/stuff/ts/package.json +++ b/stuff/ts/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "![Typescript logo](https://miro.medium.com/v2/resize:fit:1358/0*OJAUWZoGbVq--rNd.png)", "main": "index.js", + "scripts": { "build": "tsc", "build:dev": "tsc -w" diff --git a/stuff/ts/src/classesExample1.ts b/stuff/ts/src/classesExample1.ts index 279aac5..8dd1158 100644 --- a/stuff/ts/src/classesExample1.ts +++ b/stuff/ts/src/classesExample1.ts @@ -1,4 +1,4 @@ -import validateHealthAmount from "./validate"; +import { validateHealthAmount } from "./validate"; type PlayerKind = "fighter" | "swordman" | "gunman"; diff --git a/stuff/ts/src/index.ts b/stuff/ts/src/index.ts index 285054d..b319105 100644 --- a/stuff/ts/src/index.ts +++ b/stuff/ts/src/index.ts @@ -1,3 +1,5 @@ +import { sayHello } from "./validate.js"; + const sum = (a: number, b: number) => a + b; const result1 = sum(4, 2); @@ -454,3 +456,5 @@ sendNotificationMessage({ phoneNumber: 4322345221, text: "Helppp", }); + +sayHello("Jane"); diff --git a/stuff/ts/src/validate.ts b/stuff/ts/src/validate.ts index 90ba3c4..b6d83fd 100644 --- a/stuff/ts/src/validate.ts +++ b/stuff/ts/src/validate.ts @@ -8,4 +8,8 @@ const validateHealthAmount = (amount: number) => { } }; -export default validateHealthAmount; +function sayHello(name: string): void { + console.log(name); +} + +export { validateHealthAmount, sayHello }; diff --git a/stuff/ts/tsconfig.json b/stuff/ts/tsconfig.json index 3ede0f8..b7e4754 100644 --- a/stuff/ts/tsconfig.json +++ b/stuff/ts/tsconfig.json @@ -25,7 +25,7 @@ "moduleDetection": "force" /* Control what method is used to detect module-format JS files. */, /* Modules */ - "module": "commonjs" /* Specify what module code is generated. */, + "module": "ES6" /* Specify what module code is generated. */, // "rootDir": "./", /* Specify the root folder within your source files. */ "moduleResolution": "node10" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ @@ -105,6 +105,6 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "incstuff/ts/srce": ["src"] /* Files that we want to ts check */, - "exclude": ["**.test.ts"] /* TS will ignore this files*/ + "include": ["src/**/*.ts"] /* Files that we want to ts check */, + "exclude": ["**/*.test.ts"] /* TS will ignore this files*/ }