【亿码酷站-编程开发教程】收集全网优质教程及源码资源!

全网优质软件开发、平面设计等教程及精品源码资源一站可得,www.ymkuzhan.com!

两个vscode中编写typescript的好用插件推荐_亿码酷站_编程开发技术教程插图

由于项目组最近准备从javascript迁移到typescript;在使用ts过程中有部分类型定义代码片段有重复;所以编写了两个vscode插件;如有需要可以查阅。【推荐:vscode基础教程

tools1: JSON转换成typescript的interface

特色

1、从剪切板json数据转换成interface (windows: ctrl+alt+C , Mac : ^+?+C)

1.gif

2、选择json数据转换成interface (windows: ctrl+alt+S , Mac : ^+?+S)

2.gif

3、将json文件转换成interface (windows: ctrl+alt+F , Mac : ^+?+F)

两个vscode中编写typescript的好用插件推荐_亿码酷站_编程开发技术教程插图33.gif

下载

上面的gift图可能播放较快,有兴趣同学可以下载使用:打开vscode插件并搜索json转ts

两个vscode中编写typescript的好用插件推荐_亿码酷站_编程开发技术教程插图5

tools2: vscode-react-typescript-snippet

使用ts编写react代码片段。

下载

打开vscode插件并搜索vscode-react-typescript-snippet即可。

两个vscode中编写typescript的好用插件推荐_亿码酷站_编程开发技术教程插图6

支持文件

代码片段

Trigger Content
tsrcc→ react 类式组件
tsrcstate 包含Props, State, 和 constructor的类式组件
tsrpcc→ react PureComponent组件
tsrpfc react 函数式组件
tsdrpfc 拥有default export的函数式react组件
tsrfc 无状态的函数式react组件
conc→ react constructor 方法
cwm→ componentWillMount 方法
ren→ render 方法
cdm→ componentDidMount 方法
cwrp→ componentWillReceiveProps 方法
scu→ shouldComponentUpdate 方法
cwu→ componentWillUpdate 方法
cdu→ componentDidUpdate 方法
cwum→ componentWillUnmount 方法
sst→ this.setState生成
bnd→ 绑定语句
met→ 创建一个方法
tscredux→ 创建一个类式的redux,包含connect
tsrfredux-> 创建一个函数式的redux,包含connect
imt 生成一个import语句

state 相关

tsrcstate

import * as React from "react";

export interface IAppProps {}

export interface IAppState {}

export default class App extends React.Component<IAppProps, IAppState> {
  constructor(props: IAppProps) {
    super(props);

    this.state = {};
  }

  render() {
    return <div></div>;
  }
}

functional 相关

tsrfc

import * as React from "react";

interface IAppProps {}

const App: React.FC<IAppProps> = (props) => {
  return <div></div>;
};

export default App;

redux 相关

tsrcredux

import * as React from "react";
import { connect } from "react-redux";
import { Dispatch } from "redux";
// you can define global interface ConnectState in @/state/connect.d
import { ConnectState } from "@/state/connect.d";

export interface IAppProps {}

export type ReduxType = ReturnType<typeof mapStateToProps> &
  ReturnType<typeof mapDispatchToProps> &
  IAppProps;

class App extends React.Component<ReduxType> {
  render() {
    return <div></div>;
  }
}

const mapStateToProps = (state: ConnectState) => {
  return {};
};
const mapDispatchToProps = (dispatch: Dispatch) => {
  return {};
};

export default connect(mapStateToProps, mapDispatchToProps)(App);

tsrfredux

import * as React from "react";
import { connect } from "react-redux";
import { Dispatch } from "redux";
// you can define global interface ConnectState in @/state/connect.d
import { ConnectState } from "@/state/connect.d";

export interface IAppProps {}

export type ReduxType = ReturnType<typeof mapStateToProps> &
  ReturnType<typeof mapDispatchToProps> &
  IAppProps;

const App: React.FC<ReduxType> = (props) => {
  return <div></div>;
};

const mapStateToProps = (state: ConnectState) => {
  return {};
};
const mapDispatchToProps = (dispatch: Dispatch) => {
  return {};
};

export default connect(mapStateToProps, mapDispatchToProps)(App);

tsrpfc

import * as React from "react";

export interface IAppProps {}

export function App(props: IAppProps) {
  return <div></div>;
}

相关推荐:编程教学”>编程教学!!

两个vscode中编写typescript的好用插件推荐
—–文章转载自PHP中文网如有侵权请联系admin#tyuanma.cn删除

php post数据丢失怎么办

云服务器推荐