ts-node tsc指令(typescript compile)编译并执行ts文件
// 在管理员权限下 全局安装typescript和ts-node
npm install -g typescript ts-node
tsc --help // 查看指令
cnpm install axios -S
tsc index.ts // 输出结果为一个js文件
ts-node index.ts
初识ts、类型系统
例子
import axios from 'axios'
const url = 'https://jsonplaceholder.typicode.com/users/1'
axios.get(url).then(res => {
const data: IUser = res.data
const {
id, name, email, phone } = data
console.log(`id是${
id}`)
console.log(`name是${
name}`)
console.log(`email是${
email}`)
console.log(`phone是${
phone}`)
})
interface IUser {
id: number;
name: string;
username: string;
email: string;
address: IAddress;
phone: string;
website: string;
company: ICompany;
}
interface IAddress {
street: string;
suite: string;
city: string;
zipcode: string;
geo: IGeo;
}
interface IGeo {
lat: string;
lng: string

本文介绍了TypeScript的基本概念,包括初识TypeScript、类型系统、类型注解、变量和函数的类型注解、对象和数组类型、类型推断、元组类型、类型别名以及接口和类的使用。特别强调了类型注解在JSON.parse等场景中的重要性和构造器的修饰符使用规则。
最低0.47元/天 解锁文章
581

被折叠的 条评论
为什么被折叠?



