about.vue 2.54 KB
<template>
  <div />
</template>

<script setup lang="ts">
// 类装饰器、方法装饰器、属性装饰器、参数装饰器
// function addAge(constructor: Function) {
//   constructor.prototype.age = 18
// }
// @addAge
// class Person {
//   name: string;
//   age!: number;
//   constructor() {
//     this.name = 'abc'
//   }
//   say () {
//     console.warn('xxx')
//   }
// }
// let person = new Person();
// console.warn(person);
// 属性/方法装饰器
// 声明装饰器修饰方法
// function method(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
//   console.warn(target);
//   console.warn('prop ' + propertyKey);
//   console.warn('desc ' + JSON.stringify(descriptor));
//   descriptor.writable = false;
// }
// // 声明装饰器修饰属性
// function prop(target: any, key: string): any {
//   console.warn(target);
//   console.warn('prop ' + key);
//   const descriptor: PropertyDescriptor = {
//     writable: true,
//     configurable: true,
//     enumerable: true,
//     value: 'abc'
//   };
//   return descriptor;
// }
// // 类
// class Person {
//   // @prop
//   name: string;
//   constructor() {
//     this.name = 'xxx'
//   }
//   @method
//   say() {
//     return 'instance method'
//   }
//   @method
//   static run() {
//     return 'static method'
//   }
// }
// const person = new Person()
// person.name
// Person.run()
// 参数装饰器
// function logParameter(target: Object, propertyKey: string, index: number) {
//   console.log(target, propertyKey, index);
// }

// class Person {
//   greet(@logParameter message: string, @logParameter name: string): string {
//     return `${message} ${name}`;
//   }
// }
// const p = new Person('');
// p.greet('hello', 'randy');
// class Person {
//   name = 'abc'
//   constructor (name) {
//     this.name = name;
//   }
//   say() {
//     console.warn('');
//   }
// }
// import Person from '@/Person'
// class Son extends Person {
//   say () {
//     return ''
//   }
// }
// const person = new Son('')
// console.warn(person);
// type E3 = NonNullable<string | number | null | undefined>
// // let e1: E3 = 1
// let e2: E3 = undefined
// console.warn(e2);
// function getUserInfo () {
//   return 'abc'
// }
// type E = ReturnType<typeof getUserInfo>
// const user: E = {}
// console.warn(user);
// interface A {
//   a: string;
//   b: number;
//   d: boolean;
// }
// type aPartial = Partial<A>
// type Point = 'x';
// type PointList = Record<Point, { key: number }>
// const z: PointList = {
//   x: {
//     key: 1
//   }
// }
</script>

<style lang="less" scoped>
</style>