- function add(...args: string[]) {
-
- let list4: IArguments = arguments;
-
- }
-
- add('1', '2')
- interface A1 {
-
- callee: Function,
-
- length: number,
-
- [index: number]: any
-
- }
-
- function adds(...args: string[]) {
-
- let list4: A1 = arguments;
-
- }
-
- adds('1', '2')
- function add1(a: number, b: number): number {
-
- return a + b;
-
- }
-
- const add2 = (a: number, b: number): number => {
-
- return a + b;
-
- }
- const add3 = (a: number = 10, b: number = 15): number => {
-
- return a + b;
-
- }
- const add4 = (a?: number, b?: number): void => {
-
- }
- interface User {
-
- name: string,
-
- age: number
-
- }
-
- function getName(data: User): User {
-
- return data;
-
- }
//ts 可以定义this 必须是第一个参数
- interface Obj {
-
- list: number[],
-
- add: (this: Obj, num: number) => void
-
- }
-
- let obj: Obj = {
-
- list: [1, 2, 3, 4],
-
- add(this: Obj, num: number) {
-
- this.list.push(num);
-
- console.log(this.list)
-
- }
-
- }