摘要: 概要 typescript在开发过程中广泛被应用,typescript的断言特性更是重中之重,今天和大家来讨论一下as const断言。 代码和讨论 我们首先来看一段代码, 如下: let a:string = "aaa"; const b = "aaa"; 以上代码除了const和let两个关键子 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(238) 评论(0) 推荐(0)
摘要: import { Button, Dropdown, Menu, Modal, Table, TableProps } from "antd"; interface ISearchListProps extends TableProps<Project> { users: User[]; } 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(58) 评论(0) 推荐(0)
摘要: 第一种方式 第二种 3接口管理工具 4本地node服务器 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(22) 评论(0) 推荐(0)
摘要: 解决相对路径问题 ts.config.json "baseUrl": "./src", prettier yarn add --dev --exact prettier 自动格式化 npx mrm lint -staged "lint-staged": { "*.{js,css,md,ts,tsx} 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(34) 评论(0) 推荐(0)
摘要: npx create xxx 项目名 依赖按照 yarn start 进行项目运行 yarn start 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(37) 评论(0) 推荐(0)
摘要: useSearchParams 顾名思义,可以直接获取url中的query参数,而不需要引入外部库来解析路径中的query参数 import { useSearchParams} from 'react-router-dom'; // 比如 url是 /demo?name=1 function De 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(43) 评论(0) 推荐(0)
摘要: 在Typescript中,表示断言有两种方式。一种是扩号表示法: let someValue: any = "this is a string"; let strLength: number = (someValue).length; 另一种使用as关键字: let someValue: any = 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(37) 评论(0) 推荐(0)
摘要: Object.fromEntries() 方法把键值对列表转换为一个对象。 const entries = new Map([ ['foo', 'bar'], ['baz', 42] ]); const obj = Object.fromEntries(entries); console.log(o 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(21) 评论(0) 推荐(0)
摘要: 2-1、要求 自定义一个useArray的custom hook。结合react-hook和typescript,实现对数组简单的增加、删除、清空的那个功能,并且对增加的对象类型有限制 2-2、代码实现 export const useDebounce = (value, delay) => { c 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(18) 评论(0) 推荐(0)
摘要: 啥时候需要声明类型 理论上来说在我们声明任何变量的时候都需要声明类型(包括普通变量、函数、组件、hook 等等),声明 函数、组件、hook 等需要声明参数 和 返回值的类型。 但是在很多情况下,TS 可以帮我们自动推断,我们就不用声明了,比如: // 这里虽然没有显式声明,但是ts自动推断这是个n 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(36) 评论(0) 推荐(0)
摘要: TypeScript 的类型 8 种类型: number, string, boolean, 函数,array, any, void, object 这一节我们接触到了平常使用中会接触到的大部分的类型,下面我们挨个梳理一遍: number:数字类型,包含小数、其他进制的数字 let decimal: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(42) 评论(0) 推荐(0)
摘要: TypeScript vs JavaScript TypeScript 是 “强类型” 版的 JavaScript,当我们在代码中定义变量 (包括普通变量、函数、组件、hook 等) 的时候,TypeScript 允许我们在定义的同时指定其类型,这样使用者在使用不当的时候就会被及时报错提醒: int 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(35) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(33) 评论(0) 推荐(0)
摘要: const SearchPannel = ({ users, param, setParam }) => { return ( <form> <div> <input type="text" value={param.name} onChange={evt => setParam({ ...para 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(45) 评论(0) 推荐(0)
摘要: module.exports = (req, res, next) => { console.log(req,res,next,"geyao") if (req.method "POST" && req.path "/login") { if (req.body.username "jack" && 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(33) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(22) 评论(0) 推荐(0)
摘要: const SearchList = ({ lists, users }) => { return ( <table> <thead> <tr> <th>项目</th> <th>负责人</th> </tr> </thead> <tbody> { lists.map(project => <tr> < 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(26) 评论(0) 推荐(0)
摘要: Mock数据配置 安装json-server yarn add json-server -D 创建本地Mock数据库在package.json中添加script脚本 "scripts": { "start": "react-scripts start", "build": "react-script 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(33) 评论(0) 推荐(0)
摘要: commitlint代码提交语句检查 安装依赖 官方网址 yarn add --dev @commitlint/{config-conventional,cli} 新建文件 echo "module.exports = {extends: ['@commitlint/config-conventio 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(33) 评论(0) 推荐(0)
摘要: 提交自动格式化 官网地址 安装依赖 npx mrm lint-staged 解决与eslint的冲突 yarn add eslint-config-prettier -D 配置package.json "husky": { "hooks": { "pre-commit": "lint-staged" 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(33) 评论(0) 推荐(0)
摘要: prettier格式化插件 安装插件 安装依赖 yarn add --dev --exact prettier echo {}> .prettierrc.json 添加.prettierignore # Ignore artifacts: build coverage 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(26) 评论(0) 推荐(0)
摘要: 该软件包包括适用于各种浏览器的 polyfill。项目使用的最低要求和常用语言功能。 用法 首先,使用 Yarn 或 npm 安装包: npm install react-app-polyfill 或者 yarn add react-app-polyfill 支持 Internet Explorer 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(36) 评论(0) 推荐(0)
摘要: 创建项目 用脚手架创建项目 npx create-react-app jira --template typescript 在tsconfig.json中配置baseUrl "baseUrl": "./src", 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(34) 评论(0) 推荐(0)
摘要: 安装react_ts环境并与react_js对比 安装一个react_js项目 npx create-react-app 项目名安装有个react_ts项目 npx create-react-app 项目名 --template typescript 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(28) 评论(0) 推荐(0)
摘要: 创建一个vue_js项目 vue create 项目名创建一个vue_ts项目 vue create 项目名创建一个vue_vite_ts项目 npm init vite@latest 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(48) 评论(0) 推荐(0)
摘要: TS描述文件声明 TypeScript 作为 JavaScript 的超集,在开发过程中不可避免要引用其他第三方的 JavaScript 的库。虽然通过直接引用可以调用库的类和方法,但是却无法使用TypeScript 诸如类型检查等特性功能。为了解决这个问题,需要将这些库里的函数和方法体去掉后只保留 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(38) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(17) 评论(0) 推荐(0)
摘要: 安装依赖: 安装webpack环境 npm i webpack webpack-cli webpack-dev-server -D 安装TypeScript npm install typescript -D 编译TS npm install ts-loader -D 热更新服务 npm insta 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(58) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(33) 评论(0) 推荐(0)
摘要: 使用rollup打包TS文件 安装依赖: 全局安装rollup npm install rollup-g 安装TypeScript npm install typescript -D 安装TypeScript 转换器 npm install rollup-plugin-typescript2 -D 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(197) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(38) 评论(0) 推荐(0)
摘要: { "compilerOptions": { /* Visit https://aka.ms/tsconfig to read more about this file */ /* Projects */ // TS编译器在第一次编译之后会生成一个存储编译信息的文件,第二次编译会在第一次的基础上进行 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(76) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(24) 评论(0) 推荐(0)
摘要: // 1.接口 // interface ITest { // name: string // } // interface ITest { // age: number // } // class Person implements ITest { // name: string = "文咏珊" 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(34) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(19) 评论(0) 推荐(0)
摘要: /// <reference path="./namespaceTest2.ts" /> // const a: User.IName = { // uname: "万茜" // } // console.log(a); const a: User.UserInfo.IName = { uage: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(38) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:45 前端导师歌谣 阅读(22) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(28) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(28) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(21) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(27) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(53) 评论(0) 推荐(0)
摘要: import React from "react" import classNames from 'classnames' export interface MenuItemProps { index?: string; disabled?: boolean; className?: string; 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(18) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(56) 评论(0) 推荐(0)
摘要: .btn { position: relative; display: inline-block; font-weight: $btn-font-weight; line-height: $btn-line-height; color: $body-color; white-space: nowra 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(26) 评论(0) 推荐(0)
摘要: import React from "react"; import classNames from "classnames" export enum ButtonSize{ Large='lg', Small='sm' } export enum ButtonType{ Primary="prima 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(25) 评论(0) 推荐(0)
摘要: import React from "react"; import classNames from "classnames" export enum ButtonSize{ Large='lg', Small='sm' } export enum ButtonType{ Primary="prima 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(34) 评论(0) 推荐(0)
摘要: classnames可以接受很多参数 报告 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(19) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(19) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(17) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(12) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(13) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(7) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(14) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(14) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(7) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(26) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(10) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(23) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(22) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(20) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(22) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(39) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(28) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(16) 评论(0) 推荐(0)
摘要: 传入函数得含义是惰性初始化 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(16) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(16) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(10) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(8) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(15) 评论(0) 推荐(0)
摘要: 1接口调用 /*调用接口*/ created() { /*动态渲染content_type接口*/ getAction("/dict/list",{ dict_code:"content_type" }).then(res=>{ this.content_type=res.data }) /*动态渲 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(23) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(9) 评论(0) 推荐(0)
摘要: 可以监听组件得插件 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(19) 评论(0) 推荐(0)
摘要: import React from "react" import classNames from 'classnames' type MenuMode = 'horizontal' | 'vertical' export interface MenuProps { /**默认 active 的菜单项 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(19) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(14) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(15) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(13) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(11) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(13) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(10) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(7) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(7) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(10) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(12) 评论(0) 推荐(0)
摘要: const User = () => { const { logout, user } = useAuth(); return ( <Dropdown overlay={ <Menu> <Menu.Item key={"logout"}> <Button onClick={logout} type= 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(15) 评论(0) 推荐(0)
摘要: import React from "react"; import { useTasksSearchParams } from "screens/kanban/util"; import { useSetUrlSearchParam } from "utils/url"; import { Row 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(25) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(15) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(10) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(17) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(11) 评论(0) 推荐(0)
摘要: export const SearchPanel = ({ users, param, setParam }: SearchPanelProps) => { return ( <Form style={{ marginBottom: "2rem" }} layout={"inline"}> <For 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(30) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(13) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(30) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(10) 评论(0) 推荐(0)
摘要: // TS 中的typeof,是在静态环境运行的 // return (...[endpoint, config]: Parameters<typeof http>) => export const useHttp = () => { const { user } = useAuth(); // u 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(16) 评论(0) 推荐(0)
摘要: const apiUrl = process.env.REACT_APP_API_URL; interface Config extends RequestInit { token?: string; data?: object; } export const http = async ( endp 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(14) 评论(0) 推荐(0)
摘要: import React, { useState } from "react"; import { RegisterScreen } from "unauthenticated-app/register"; import { LoginScreen } from "unauthenticated-a 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(13) 评论(0) 推荐(0)
摘要: const AuthContext = React.createContext< | { user: User | null; register: (form: AuthForm) => Promise<void>; login: (form: AuthForm) => Promise<void>; 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(17) 评论(0) 推荐(0)
摘要: const AuthContext = React.createContext< | { user: User | null; register: (form: AuthForm) => Promise<void>; login: (form: AuthForm) => Promise<void>; 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(16) 评论(0) 推荐(0)
摘要: // 在真实环境中,如果使用firebase这种第三方auth服务的话,本文件不需要开发者开发 import { User } from "types/user"; const apiUrl = process.env.REACT_APP_API_URL; const localStorageKey 阅读全文
posted @ 2022-10-07 18:44 前端导师歌谣 阅读(16) 评论(0) 推荐(0)