码迷,mamicode.com
首页 > 其他好文 > 详细

TypeScript 学习

时间:2020-07-15 23:48:10      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:div   round   vscode   type   declare   编译   str   script   class   

1. typescript 中的declare 表示声明 一个类或接口后,可以不引入既可以被编译器识别,做为类型使用

如: 在 a.ts 中 定义了

 

declare class A{

name:string;

age:number;

}

 

在b.ts 中可以使用

let a:A = {name:"12",age:12};

在vscode 中不会报错,但是使用 tsc 编译 b.ts 会报错,因为没有引入A.,如果import 了 A就可以正常编译成js.

但是奇怪的是在 vue 的typescript 版本中使用可以正常打包,在不引入类型的情况下使用,可以作为 接口返回类型的约定,或只作为类型不使用new 创建。

 

2. d.ts 是声明文件。d.ts里面的东西不能被引入,只能作为类型来用,d.ts里面的东西也不会被编译成js,只是作为编译阶段被识别。

 

TypeScript 学习

标签:div   round   vscode   type   declare   编译   str   script   class   

原文地址:https://www.cnblogs.com/chillaxyw/p/13307641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!