摘要:
访问类型有 private, protected, public class Person { name: string; public sayHi() { console.log(this.name); // 类内调用 } } class Teacher extends Person{ publi 阅读全文
摘要:
class Person{ } 这就是 ts 里面最基础的类 class Person { name = 'zina'; getName() { return this.name } } // 有了类后创建一个实例 const person = new Person(); console.log(p 阅读全文
摘要:
const getPersonName = person => { console.log(person.name); } const setPersonName = (person, name) => { person.name = name; } /** * 这是没用 ts 语法,这样会有问题, 阅读全文
摘要:
/** * TS 数组和 JS 数组是一样的 * 变量提示,const numberArr: number[] */ const numberArr = [1, 2, 3]; const arr: number[] = [1,2,3]; const stringArr: string[] = ['a 阅读全文
摘要:
// JS 中定义函数的方式 function hell(){} const hello1 = function(){} const hello2 = () => {} // TS 中定义函数的方式 // 参数需要类型注解,返回值不需要 function add(first: number, sec 阅读全文
摘要:
// type annotation 类型注解,我们来告诉 TS 变量是什么类型 // type inference 类型推断,TS 会自动的去尝试分析变量的类型 // 如果 TS 能够自动分析变量类型,我们就什么也不需要做了 // 如果 TS 无法分析变量类型的话,我们就需要使用类型注解 let 阅读全文
摘要:
// 基础类型 null, undefined, symbol, boolean, void const count: number = 123; const teacherName: string = 'zina'; *:如果基础类型是一行的,ts 能推断出它的类型,如果是两行就不一定了 let 阅读全文
摘要:
学 TypeScript 就是在学 TypeScript 的静态类型和 JavaScript 的衍生语法 const count: number = 2019; // 按照之前的理解,count 是个 number 类型的静态类型。不能变更为其他类型 count.toFixed(); // coun 阅读全文
摘要:
要运行 TypeScript,需要一个 node 的运行环境, 1、安装 node,http://nodejs.cn/download/, 输入 node -v, npm -v 能争取输出版本好, node 安装就没有问题了 2、配置 vsCode,打开 Code - Preferences - S 阅读全文
摘要:
demo.js function demo(data) { return Math.sqrt(data.x ** 2 + data.y ** 2); } demo(); demo.ts function tsDemo(data:{x: number, y: number}) { return Mat 阅读全文