Jest: testEnvironent
The following two Code snippets, one is seriver-side tests, and one is react componet tests. dbConnect TestSuite is server side tests, use node for testEnvironment. This React Unit Test file, …
Jest? and What are sub, fake, mock?
npm install –save-dev jest @types/jest npm install –save-dev ts-jest npx ts-jest config:init will generate file jest.config.js create __tests__ folder under root path of Next.js project, and create xxx.test.ts under this …
Mongoose 「蒙古斯」(/ˈmɒŋ.ɡuːs/)
We access MongoDB through Mongoose module. We create these ts file to access MongoDB. (Example: Next.js Project, npm install mongoose) When you need to define an interface in TypeScript but …
GraphQL on Next.js
GraphQL has the built-in scale types Int, Float, String, Boolean, and ID. Exclamation marks (!) denote non-nullable fields, and lists within square brackets([ ]) indicate arrays. use browser http://localhost: 3000/api/graph …
Next.js Rendering: SSR, SSG, ISR, CSR
Server-Side Rendering: SSR 何時執行? 每次請求時,在伺服器端執行 getServerSideProps 來產生 HTML。優點: 缺點: Static Site Generation: SSG 何時執行? 在 build 時執行 getStaticProps,預先生成 HTML,並在 CDN 上提供。優點: 缺點: Incremental Static Regeneration: ISR 何時執行? 在 build 時先生成靜態頁面,但允許根據 …
React
React uses a custom JavaScript Syntax Extension (JSX) to describe HTML elements and TypeScript for static typing, both of which require a transpiler to convert the code to JavaScript. To …
Let Express.js support TypeScipt
目前有三個ts檔案,分別為custom.d.ts, routes.ts, index.ts 當各別下tsc custom.d.ts, tsc routes.ts, tsc index.ts, 與在資料夾的根目錄下npx tsc的結果不一樣。當各別下時,需在routes.ts的開頭加入/// ,且當下tsc index.ts時會出現錯誤:index.ts:2:8 – error TS1259: Module ‘”/mnt/c/cmder/Project/Book/Node.js/sample-express/node_modules/@types/express/index”‘ can only be default-imported using the ‘esModuleInterop’ flag 2 import express, { …
TypeScript Built-in Types
Primitive JavaScript Types The union Type The array Type The tuple Type The any Type The void Type The object Type Custom Types and interface
traditional() vs arrow()
分析 traditional() 方 理解 this 綁定 等價於: javascript複製編輯console.log(scopeOf.traditional()); // 相當於 scopeOf.traditional.call(scopeOf); 因此: javascript複製編輯this === scopeOf; // ✅ this 綁定到 scopeOf this.scope === “defining scope”; // ✅ 回傳 “defining scope” 分析 …