ICode9

精准搜索请尝试: 精确搜索
  • [Typescript Challenges] 1. Easy - Pick2022-08-31 15:30:29

    For example: interface Todo { title: string description: string completed: boolean } type TodoPreview = MyPick<Todo, 'title' | 'completed'> const todo: TodoPreview = { title: 'Clean room', completed: fal

  • 使用 Typescripts Interface Props 检查 PropTypes 的最佳方式2022-08-31 09:33:07

    使用 Typescripts Interface Props 检查 PropTypes 的最佳方式 介绍 你可能正在开发一个使用 Typescript 构建的 React 应用程序,并且需要支持 PropTypes。为什么你需要他们两个?好吧,每种解决方案都有不同的用途。 PropTypes 在运行时检查,而 Typescript 在编译时验证类型。 就我而言

  • 对 TypeScript 友好(第 2 部分):超级友好的初学者指南2022-08-31 04:00:51

    对 TypeScript 友好(第 2 部分):超级友好的初学者指南 本文适用于任何试图掌握 TypeScript 世界的人。 建议阅读 “对 TypeScript 友好(第 1 部分):超级友好的初学者指南” 在阅读本文之前。 本文将涵盖: 类型注释 类型断言 类型和接口的区别 可选属性 很多简单的代码示例 Photo by Al

  • 2022 年 8 月前端更新:TypeScript、软件设计模式、焦点样式和单个 CSS 转换属性中的 SOLID 原则2022-08-31 03:32:03

    2022 年 8 月前端更新:TypeScript、软件设计模式、焦点样式和单个 CSS 转换属性中的 SOLID 原则 本月我们将介绍 TypeScript 中的 SOLID 原则、React 应用程序的软件设计模式、焦点样式和新的单独 CSS 转换属性。 由 Whitespectre 工程团队提供 August 2022 Frontend Updates: SOL

  • [Typescript] Step 3. Turn on "noImplicitAny" and even more strict mode2022-08-29 19:00:51

    Step 3: Turn on "noImplicitAny" From previous steps, we allow implicit any: https://www.cnblogs.com/Answer1215/p/16634618.html   Now, we need to turn on "noImplicitAny" mode. tsconfig.json "noImplicitAny": true,   Example com

  • [Typescript] Step1 & 2 for converting a js app to ts2022-08-29 01:30:18

    1. Compiling in "loose mode" Start with all tests passing Rename all .js to .ts, allowing implicit any Fix only things that are not type-checking, or causing compile errors Be careful to avoid changing behavior of function Get test passing agai

  • Vite + Vue3 + Pinia + es6 + TypeScript 搭建项目2022-08-27 17:01:15

    vite 中文参考文档:https://vitejs.cn/guide/#scaffolding-your-first-vite-project 执行  npm init vite@latest 步骤如下图: 下载依赖 npm i  启动项目: npm run dev       pinia文档:https://pinia.web3doc.top/ vuex4文档:https://vuex.vuejs.org/zh/installation.html pini

  • vscode中使用prettier和typescript2022-08-24 20:00:32

    参考博文 文章标题:How to use Prettier with ESLint and TypeScript in VSCode 链接:https://khalilstemmler.com/blogs/tooling/prettier/ 总结 使用npm安装prettier npm install --save-dev prettier 新增.prettierrc配置文件,需要对哪些内容进行格式化 { "useTabs": false

  • [Typescript] Toolbox: isError2022-08-24 14:31:38

    function isError(err: any): err is Error { return err instanceof Error; } try { somethingRisky() } catch(err: unknown) { if (isError(err)) { console.log(err.stack) } else { console.log(err) } }   You can also have the following in test

  • [Typescript] ts-expect-error2022-08-24 02:00:10

    In some ways // @ts-expect-error can act as a suppression comment, similar to // @ts-ignore. The difference is that // @ts-ignore will do nothing if the following line is error-free. For example: of course, "string" is not a number. but, when

  • [Typescript] Filtering properties out2022-08-21 00:30:41

    List all the props with begin with "query" key in Document type queryTypes = Extract<keyof Document, `query${string}`> type queryyPoprDoc = { [Key in queryTypes]: Document[Key] } What if we want to filter out by value? For example we w

  • Vue3 + Socket.io + Knex + TypeScript 实现可以私聊的聊天室2022-08-20 15:03:13

    前言 下文只在介绍实现的核心代码,没有涉及到具体的实现细节,如果感兴趣可以往下看,在文章最后贴上了仓库地址。项目采用前后端模式,前端使用 Vite + Vue3 + TS;后端使用 Knex + Express + TS。目前项目还没有完全实现,文章的目的是记录阶段性“胜利”和分享知识。 关于搭建 TS 项目请看

  • [Typescript] Pick partially object type with indexed access types2022-08-18 19:32:44

    type PartOfWindow = { [Key in | "document" | "navigator" | "setTimeout"]: Window[Key] } /* type PartOfWindow = { document: Document; navigator: Navigator; setTimeout: (handler: TimerHandler,

  • [Typescript] Index access types2022-08-16 21:34:29

    Indexed Access types provide a mechanism for retrieving part(s) of an array or object type via indices. We’ll look at how this kind of type works, and a couple of practical examples of where you might use them. interface Car { make: string model: stri

  • [Typescript] Extract & Exclude2022-08-15 19:01:55

    Extract is useful for obtaining some sub-part of a type that is assignable to some other type. type FavoriteColors = | "dark sienna" | "van dyke brown" | "yellow ochre" | "sap green" | "titanium white

  • [Typescript] Making TypeScript Stick - 5 - Extends2022-08-15 02:00:12

    Let’s study a few examples of extends scenarios and see if we can figure out whether it will evaluate to true or false 64 extends number . . . Answer: 查看代码  true   number extends 64 . . . Answer: 查看代码  false     string[] extends any . .

  • TypeScript 项目报错 Unknown file extension ".ts"2022-08-15 01:30:35

    下面是更详细的报错图: 这个报错我也是在网上搜了好多好久也没有解决的问题,最终通过 GitHub 的一个 Issue 找到了外网解决这个错误的帖子:ts-node execute typescript with module import and module defined。 下面有一个人是这样回应的: 他的意思就是我们不需要给 package.json

  • Nodemon 如何实时监听 TypeScript 项目下的文件并热部署?2022-08-15 01:30:08

    首先你的项目要安装ts-node和nodemon: npm i -D ts-node nodemon 在package.json文件中配置运行脚本: "dev": "nodemon --watch src/**/*.ts --exec \\\"ts-node\\\" src/main.ts", 这一条脚本的最后那是你项目的入口文件,根据你的项目实际情况修改目录。

  • 搭建 Webpack + TypeScript + Babel 的项目2022-08-14 01:30:35

    安装依赖包 首先把 webpack 相关的依赖安装了: npm i -D webpack webpack-cli 安装各个 loader: npm i -D ts-loader babel-loader source-map-loader 安装 babel 的核心: npm i -D @babel/core 安装 babel 的 preset: npm i -D @babel/preset-env @babel/preset-typescript 安装

  • simpread-TypeScript interface 与 type 的区别2022-08-13 16:32:44

    interface 和 type 在 TypeScript 中的区别 1、TypeScript interface 和 type 的介绍 在 TypeScript 中,interface 更偏于一种约束类型,而 type 的作用就是给类型起一个新名字,也就是别名。后来随着 TypeScript 语言的发展,type 被赋予了新的内涵,type 也可以用来定义类型。 约束类型与

  • 一个typescript版本的dao(数据库访问)层的封装2022-08-12 17:01:23

    首先学会使用mustache语法 select * from {{key1}}字符中{{key1}}会进行匹配map中的key 例如: let sql = select * from {{key1}}; let tableMapper = { "key1": "course", } let result = mustache.render(sql, tableMapper); console.log('

  • [Typescript] namespace2022-08-08 18:31:04

    `namespace` is manily for the left over from the days where we’d refer to libraries through a single global variable. With this in mind, let’s not give namespace too much more thought for now. For example: // using $ as class calling static method $.ajax(

  • [Typescript] Generics constraint2022-08-08 18:02:38

    Assume we have the following code: interface HasId { id: string } interface Dict<T> { [k: string]: T } function listToDict<T>(list: T[]): Dict<T> { const dict: Dict<T> = {} list.forEach((item) => { // Property &#

  • 一篇够用的TypeScript总结2022-08-08 16:32:48

    ts的优缺点 1、优点 代码的可读性和可维护性:举个

  • typeScript 基础点2022-08-08 16:01:31

    // ts 数据类型 // 1. 基本数据类型: string, number, boolean, undefined, null let s:string = 'aaaa' // 2. 数组: number[] 泛型写法:Array<number> let arr:number[] = [1,2,3] let arr1:Array<string> = ['1', '2', '3'] //3.

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有