Giter VIP home page Giter VIP logo

ts-noobcoding's Introduction

工程用途

用途 情景
做算法题 使用 c++java 当然很好,但前端新手写 ts 可以加深理解,js 语法松散,无论项目和做算法题都可以尝试用 ts
熟悉 ts 基础 仓库环境涉及 jestbabel 的常见使用场景,可以在此基础上添加 expresscanvas 类似框架直接搭建成后端项目、服务

脚手架教程

构建项目

首先 clone 项目到本地,进行 node 相关初始化后,使用 webstormvscode 编辑代码

  • 单元测试:在 /src/tests 文件夹中,通过 pnpm test <fileName> 进行某个文件的单元测试,若置空则会进行所有 .spec.ts 文件的测试
  • 全局类型定义:在项目根目录的 global.d.ts

搭建过程

整个项目搭建的流程记录,仅供参考

  1. 初始化 node.js 和 pnpm
  2. 安装 ts 支持
    • pnpm add typescript --save-dev
    • npx tsc --init 初始化 tsconfig.json
  3. 安装 jest 并支持 type
    • pnpm add jest @types/jest --save-dev
  4. node 环境下一般仅支持 cjs 模块,通过 babel 配置 es 模块,并支持 type
    • pnpm add babel-jest @babel/core @babel/preset-env --save-dev
    • pnpm add @babel/preset-typescript --save-dev
  5. 初始化 babel.config.js 配置与 node 版本兼容的 babel
    module.exports = {
      presets: [
        ['@babel/preset-env', { targets: { node: 'current' } }],
        '@babel/preset-typescript',
      ],
    }
  6. 添加 node (package.json) -> scripts
    "scripts": {
       "test": "jest"
    }
    
  7. 根据你的习惯,添加 src/utils、src/tests 等文件夹,开始编码

安装 eslint

  1. 安装 eslint
    • pnpm i eslint -D
  2. 安装 ts 解析器
    • pnpm i @typescript-eslint/parser -D
    • pnpm i @typescript-eslint/eslint-plugin -D
  3. 安装 js 代码规范
    • pnpm i eslint-config-standard -D
    • pnpm i eslint-plugin-import eslint-plugin-node eslint-plugin-promise -D
  4. 安装 prettier
    • pnpm i prettier -D
    • pnpm install prettier-eslint eslint-plugin-prettier eslint-config-prettier -D

ts-noobcoding's People

Contributors

nesb01t avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.