本文共 3001 字,大约阅读时间需要 10 分钟。
npm install -g typescript @typescript ts-node
ts-node -p tsconfig.json
interface Animal { color: string; height: number;}let a: Animal = { color: 'gold', height: 30,}; interface Person { name: string; age: number; car?: string; // 可选属性}let liujin: Person = { name: '刘劲', age: 18, // car: '共享单车'}; interface LogA { (a: number, b: number): number;}let add: LogA = (a: number, b: number) => { return a + b;};let minus: LogA = (a: number, b: number) => { return a - b;};console.log(add(4, 8));console.log(minus(30, 10)); interface People { name: string; fun(): void;}let p1: People = { name: '赵丽颖', fun(): void { console.log('这是调用接口的方法'); }};console.log(p1); class Man implements LogB { name: string = '唐达'; fun(): void { console.log('这是调用接口的方法'); }}let tangda = new Man();console.log(tangda.name);tangda.fn(); interface D extends A { fn2(): void;}class E implements D { fn(): void { console.log('实现了A接口'); } fn2(): void { console.log('实现了D接口'); }}let e = new E();e.fn();e.fn2(); function logC(params: any) { return function(target: any) { console.log('params:', params); console.log('target:', target.name); target.prototype.age = params; target.prototype.fn = () => { console.log('该方法被调用了'); }; }}@logC('小王')class Http1 { name: string | undefined = '哈哈'; age: string | undefined; fn(): void { }}let h = new Http1();console.log(h.age);h.fn(); function logD(params: any) { return function(target: any, attr: any) { console.log('params:', params); console.log('target:', target); console.log('attr:', attr); target[attr] = params; }}@logD('属性装饰器')class Http2 { name: string | undefined = '属性装饰器';}let h2 = new Http2();console.log(h2.name); function logE(params: any) { return function(target: any, funName: any, desc: any) { console.log('params:', params); console.log('target:', target); console.log('funName:', funName); console.log('desc:', desc); }}@logE('方法装饰器')class Http3 { fn(): void { var num: number = 20; }} npm install -g @vue/cli@3.0.0vue create
vue create demo3.0
npm run serve
class Child { @Prop() newname: string | undefined;} const vueConfig = { publicPath: '/', outputDir: 'dist', assetsDir: 'static', indexPath: 'index.html', devServer: { proxy: { '/api': { target: 'https://example.com', ws: true, changeOrigin: true } } }}; 转载地址:http://nxse.baihongyu.com/