├── .env.example ├── .gitpod.yml ├── server.ts ├── fly.toml ├── math.handler.ts ├── Dockerfile ├── LICENSE ├── .github └── workflows │ └── fly-deploy.yml ├── package.json ├── index.ts ├── .gitignore ├── .dockerignore ├── __test__ └── math.test.ts ├── README.md └── tsconfig.json /.env.example: -------------------------------------------------------------------------------- 1 | # choose a port here 2 | PORT= -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | # This configuration file was automatically generated by Gitpod. 2 | # Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) 3 | # and commit this file to your remote git repository to share the goodness with others. 4 | 5 | # Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart 6 | 7 | tasks: 8 | - init: npm install && npm run build 9 | command: npm run start 10 | 11 | 12 | -------------------------------------------------------------------------------- /server.ts: -------------------------------------------------------------------------------- 1 | import dotenv from 'dotenv'; 2 | import { app } from './index'; 3 | 4 | /* 5 | This file imports the actual routes from our index file 6 | 7 | @see ./index.ts 8 | */ 9 | 10 | // Import .env file as enviroment variables 11 | dotenv.config(); 12 | 13 | // Check which port the server should run on 14 | const port = process.env.PORT || 8000; 15 | 16 | // Listen on the port to accept http connections 17 | app.listen(port, () => { 18 | console.log(`Server running on port http://localhost:${port}`); 19 | }); 20 | -------------------------------------------------------------------------------- /fly.toml: -------------------------------------------------------------------------------- 1 | # fly.toml app configuration file generated for simple-math-api-exercise on 2024-03-11T23:13:09Z 2 | # 3 | # See https://fly.io/docs/reference/configuration/ for information about how to use this file. 4 | # 5 | 6 | app = 'simple-math-api-exercise' 7 | primary_region = 'mad' 8 | 9 | [build] 10 | 11 | [http_service] 12 | internal_port = 3000 13 | force_https = true 14 | auto_stop_machines = true 15 | auto_start_machines = true 16 | min_machines_running = 0 17 | processes = ['app'] 18 | 19 | [[vm]] 20 | size = 'shared-cpu-1x' 21 | 22 | [env] 23 | PORT = 3000 24 | -------------------------------------------------------------------------------- /math.handler.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file contains our wonderful maths library 3 | * 4 | * @format 5 | * @see Math documentation: https://en.wikipedia.org/wiki/Mathematics 6 | */ 7 | 8 | const addTwoNumbers = (a: number, b: number): number => a + b; 9 | 10 | const divideTwoNumbers = (a: number, b: number): number => { 11 | if (b == 0) return NaN; 12 | return a / b; 13 | }; 14 | 15 | const subtractTwoNumbers = (a: number, b: number): number => a - b; 16 | 17 | const powerTwoNumbers = (a: number, b: number): number => a ** b; 18 | 19 | const multiplyTwoNumbers = (a: number, b: number): number => a * b; 20 | 21 | export { 22 | addTwoNumbers, 23 | divideTwoNumbers, 24 | powerTwoNumbers, 25 | multiplyTwoNumbers, 26 | subtractTwoNumbers, 27 | }; 28 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax = docker/dockerfile:1 2 | 3 | # Adjust NODE_VERSION as desired 4 | ARG NODE_VERSION=20.9.0 5 | FROM node:${NODE_VERSION}-slim as base 6 | 7 | LABEL fly_launch_runtime="Node.js" 8 | 9 | # Node.js app lives here 10 | WORKDIR /app 11 | 12 | # Set production environment 13 | ENV NODE_ENV="production" 14 | 15 | 16 | # Throw-away build stage to reduce size of final image 17 | FROM base as build 18 | 19 | # Install packages needed to build node modules 20 | RUN apt-get update -qq && \ 21 | apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3 22 | 23 | # Install node modules 24 | COPY --link package-lock.json package.json ./ 25 | RUN npm ci --include=dev 26 | 27 | # Copy application code 28 | COPY --link . . 29 | 30 | # Build application 31 | RUN npm run build 32 | 33 | # Remove development dependencies 34 | RUN npm prune --omit=dev 35 | 36 | 37 | # Final stage for app image 38 | FROM base 39 | 40 | # Copy built application 41 | COPY --from=build /app /app 42 | 43 | # Start the server by default, this can be overwritten at runtime 44 | EXPOSE 3000 45 | CMD [ "npm", "run", "start" ] 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Sérgio Henriques 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/fly-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy to Fly 2 | on: [push] 3 | jobs: 4 | test: 5 | name: Test 6 | runs-on: ubuntu-latest 7 | steps: 8 | # Checkout to repo 9 | - uses: actions/checkout@v4 10 | # Initialize fly.io CLI 11 | - uses: superfly/flyctl-actions/setup-flyctl@master 12 | - name: Use Node.js 13 | uses: actions/setup-node@v4 14 | with: 15 | node-version: '20.x' 16 | - run: npm install 17 | - run: npm run test 18 | deploy: 19 | name: Deploy proxy 20 | runs-on: ubuntu-latest 21 | environment: production 22 | steps: 23 | # Checkout to repo 24 | - uses: actions/checkout@v4 25 | # Initialize fly.io CLI 26 | - uses: superfly/flyctl-actions/setup-flyctl@master 27 | - name: Use Node.js 28 | uses: actions/setup-node@v4 29 | with: 30 | node-version: '20.x' 31 | - run: npm install 32 | - run: npm run build 33 | - run: npm run test 34 | # Deploy to fly.io with a remote runner 35 | - run: flyctl deploy --remote-only 36 | env: 37 | FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple-math-api-exercise", 3 | "version": "1.0.0", 4 | "description": "Node.js + express math api", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "tsc", 8 | "start": "node dist/server.js", 9 | "test": "jest", 10 | "test:watch": "jest --watch", 11 | "test:coverage": "jest --coverage" 12 | }, 13 | "jest": { 14 | "preset": "ts-jest", 15 | "testEnvironment": "node", 16 | "setupFilesAfterEnv": [], 17 | "testPathIgnorePatterns": [ 18 | "node_modules/", 19 | "dist/" 20 | ] 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/Unisergius/simple-math-api-exercise.git" 25 | }, 26 | "keywords": [], 27 | "author": "", 28 | "license": "ISC", 29 | "bugs": { 30 | "url": "https://github.com/Unisergius/simple-math-api-exercise/issues" 31 | }, 32 | "homepage": "https://github.com/Unisergius/simple-math-api-exercise#readme", 33 | "dependencies": { 34 | "dotenv": "^16.0.3", 35 | "supertest": "^6.3.4", 36 | "express": "^4.18.3" 37 | }, 38 | "devDependencies": { 39 | "@types/express": "^4.17.17", 40 | "@types/jest": "^29.5.0", 41 | "@types/node": "^18.15.5", 42 | "jest": "^29.5.0", 43 | "ts-jest": "^29.0.5", 44 | "typescript": "^5.0.2" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import express, { Express, Request, Response } from 'express'; 2 | import { 3 | addTwoNumbers, 4 | divideTwoNumbers, 5 | powerTwoNumbers, 6 | multiplyTwoNumbers, 7 | subtractTwoNumbers, 8 | } from './math.handler'; 9 | 10 | const app: Express = express(); 11 | 12 | interface Operations { 13 | [key: string]: (a: number, b: number) => number; 14 | } 15 | 16 | const operations: Operations = { 17 | 'add': addTwoNumbers, // Ensure your math handlers are properly typed in their respective files 18 | 'div': divideTwoNumbers, 19 | 'subtract': subtractTwoNumbers, 20 | 'multiply': multiplyTwoNumbers, 21 | 'power': powerTwoNumbers, 22 | }; 23 | 24 | const validateNumbers = (a: string, b: string, res: Response): boolean => { 25 | const numRegex: RegExp = /^-?\d+\.?\d*$/; 26 | if (!numRegex.test(a) || !numRegex.test(b)) { 27 | res.status(400).json({ error: 'Invalid input, numbers required.' }); 28 | return false; 29 | } 30 | return true; 31 | }; 32 | 33 | app.get('/:operation/:a/:b', (req: Request, res: Response) => { 34 | const { operation, a, b } = req.params; 35 | 36 | const operationFunction = operations[operation]; 37 | if (!operationFunction) { 38 | res.status(404).json({ error: 'Operation not supported.' }); 39 | return; 40 | } 41 | 42 | if (!validateNumbers(a, b, res)) return; 43 | if (operation === 'div' && Number(b) === 0) { 44 | res.status(400).json({ error: 'Division by zero is not allowed.' }); 45 | return; 46 | } 47 | 48 | const result: number = operationFunction(Number(a), Number(b)); 49 | res.json({ 50 | message: `${operation.charAt(0).toUpperCase() + operation.slice(1)} Operation`, 51 | operation: 'success', 52 | a, 53 | b, 54 | result, 55 | }); 56 | }); 57 | 58 | app.get('/', (_req: Request, res: Response) => { 59 | res.json({ 60 | message: 'Welcome to the Math API', 61 | endpoints: Object.keys(operations).map((op: string) => ({ 62 | path: `/${op}/:a/:b`, 63 | description: `Performs the ${op} operation on two numbers.`, 64 | })), 65 | }); 66 | }); 67 | 68 | export { app }; 69 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | # dsStore 107 | .DS_Store -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | # dsStore 107 | .DS_Store -------------------------------------------------------------------------------- /__test__/math.test.ts: -------------------------------------------------------------------------------- 1 | /** @format */ 2 | import { 3 | addTwoNumbers, 4 | divideTwoNumbers, 5 | powerTwoNumbers, 6 | multiplyTwoNumbers, 7 | subtractTwoNumbers, 8 | } from '../math.handler'; 9 | 10 | /* 11 | This file includes a battery of test for the math library we created. Using 12 | Jest, we can describe a group of tests and run them. 13 | 14 | @see Jest's Docs: https://jestjs.io/ 15 | */ 16 | 17 | // 'describe' groups tests so that they appear together when ran 18 | describe('test math handler', (): void => { 19 | // The test function will execute the closure given watching for any errors 20 | // thrown 21 | test('add two numbers', (): void => { 22 | // This test is simple, what we want to know is if the number 29 and the 23 | // number 3 using this function will result in the number 32. This is a 24 | // very crude test to test our function as it could just be always giving 25 | // out the number 32! 26 | let a = 29, 27 | b = 3; 28 | let result = addTwoNumbers(a, b); 29 | // The expect function will return a Jest object with the result we gave it 30 | // to actually test if the result we gave it is what we want, we need to use 31 | // the `toBe` method of the object to assert equality. If the values are not 32 | // equal, an error will be thrown, shown in the Jest cli 33 | expect(result).toBe(32); 34 | // In reality, the 'add two numbers' test would be a group of tests, for 35 | // edge cases, like adding negative numbers, adding numbers with different 36 | // signs, adding floating point numbers, adding NaN numbers, adding 37 | // infinities, passing strings into the parameters or other types. 38 | }); 39 | 40 | // The following tests have been collapsed for brevety 41 | test('divide two numbers', (): void => { 42 | expect(divideTwoNumbers(10, 2)).toBe(5); 43 | expect(divideTwoNumbers(1, 0)).toBe(NaN); 44 | }); 45 | 46 | test('sub two numbers', (): void => { 47 | expect(subtractTwoNumbers(5, 3)).toBe(2); 48 | }); 49 | 50 | test('power two numbers', (): void => { 51 | expect(powerTwoNumbers(10, 25)).toBe(10000000000000000000000000); 52 | }); 53 | 54 | test('multiply two numbers', (): void => { 55 | expect(multiplyTwoNumbers(2, 3)).toBe(6); 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simple-math-api-exercise 2 | 3 | Node.js + Express + TypeScript math api 4 | 5 | Here's a skeleton for us to clone in the 6th fCC meetup in Ikea 6 | 7 | ## Development 8 | 9 | This project requires Node.JS installed, a JavaScript runtime that runs code 10 | inside a v8 engine without a browser. See more on how to install it at 11 | [nodejs.org](https://nodejs.org/en). 12 | 13 | Clone it and start from there. 14 | 15 | ```sh 16 | git clone https://github.com/Unisergius/simple-math-api-exercise.git 17 | # or over ssh 18 | git clone git@github.com:Unisergius/simple-math-api-exercise.git 19 | ``` 20 | 21 | To install this project's dependencies, you have to run the following command 22 | from a terminal inside the project's directory. 23 | 24 | ```sh 25 | # change into the git's directory if needed 26 | cd simple-math-api-exercise 27 | # install dependencies 28 | npm install 29 | ``` 30 | 31 | This installs the node dependencies into the node_modules directory, what some 32 | may know them as vendors folder. 33 | 34 | The dependencies for this project are bellow with a few links on how they work 35 | and their documentaion: 36 | 37 | * [Express 4 API](https://expressjs.com/en/4x/api.html) 38 | * [TypeScript](https://www.typescriptlang.org/) 39 | * [Jest 29.5 Docs](https://jestjs.io/docs/29.5/getting-started) 40 | 41 | Node.js executes JavaScript code, but as you can see this project uses 42 | TypeScript as its scripting language. What this means is that our code is type 43 | checked using TypeScript but needs to be compiled for Node.js to be able to 44 | read our code. 45 | 46 | To compile the code to JavaScript you can run the build command using npm. This 47 | is actually running the TypeScript compiler using `tsc`, the reason to not 48 | directly run the `tsc` command is that you may not have TypeScript installed 49 | globally in your system. This is actually good since it forces your machine to 50 | run the TypeScript compiler for the verison defined in the dependencies. 51 | 52 | ```sh 53 | npm run build 54 | ``` 55 | 56 | Our server is written is Express, a Node.js library that facilitates the 57 | handling of http requests to a server in JavaScript. Our handlers are all 58 | inside of the [index.ts](./index.ts) file. Go take a look. 59 | 60 | To start the Express application, run the following command: 61 | 62 | 63 | ```sh 64 | npm start 65 | # or if you need to rebuild and run again 66 | npm run build && npm start 67 | ``` 68 | 69 | To change the `port` the web server runs on, you can create a copy of the 70 | `.env.example` file and rename it to `.env`, then write the port into the 71 | variable. 72 | 73 | ```dotenv 74 | PORT=8080 75 | ``` 76 | 77 | Antoher way to set the port without the need to create a `.env` file is to 78 | set the enviroment variable like bellow 79 | 80 | ```sh 81 | export PORT=8080 82 | npm start 83 | # or just 84 | PORT=8080 npm start 85 | ``` 86 | 87 | ## Testing 88 | 89 | Now that we have the basics of how to run the application, we need to test make 90 | the application bullet-proof. This project includes Jest as a dependency and 91 | has some simple tests inside the [__test__](./__test__) directory to make sure 92 | our math library works like intended. 93 | 94 | To just run the tests, run the following command: 95 | 96 | ```sh 97 | npm run test 98 | ``` 99 | 100 | Jest includes a tool to check if you've covered all of your possible use cases 101 | within your code. This type of checking is called Code Coverage, where your 102 | code is analysed by a software that checks every possible coditional path 103 | inside of your code, then checks which paths your tests actually run through 104 | and when it finishes it outputs a percentage value of how much of your code is 105 | actually covered by test cases. To read more about code coverage, you can read 106 | the [wikipedia article](https://en.wikipedia.org/wiki/Code_coverage). 107 | 108 | To run the coverage check, run the following command: 109 | 110 | ```sh 111 | npm run test:coverage 112 | ``` 113 | 114 | ## From Scratch 115 | 116 | This project is based on a logrocket article: 117 | [Setup node express typescript server](https://blog.logrocket.com/how-to-set-up-node-typescript-express/), 118 | to start from scratch: 119 | 120 | ```sh 121 | # Initialize a npm project 122 | npm init -y 123 | # Install deployment dependencies 124 | npm install express dotenv 125 | # Install development dependencies 126 | npm i -D typescript @types/express @types/node 127 | ``` 128 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "commonjs", /* Specify what module code is generated. */ 29 | // "rootDir": "./", /* Specify the root folder within your source files. */ 30 | // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 42 | // "resolveJsonModule": true, /* Enable importing .json files. */ 43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 45 | 46 | /* JavaScript Support */ 47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 50 | 51 | /* Emit */ 52 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 58 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 59 | // "removeComments": true, /* Disable emitting comments. */ 60 | // "noEmit": true, /* Disable emitting files from a compilation. */ 61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 68 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 75 | 76 | /* Interop Constraints */ 77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ 79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 80 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 82 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 83 | 84 | /* Type Checking */ 85 | "strict": true, /* Enable all strict type-checking options. */ 86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 104 | 105 | /* Completeness */ 106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 108 | } 109 | } 110 | --------------------------------------------------------------------------------