小编Shi*_*pta的帖子

Typescript:无法调用类型缺少调用签名的表达式。类型“号码”没有兼容的呼叫签名

我知道以前曾问过这类问题,但我仍然不清楚。

我是一个初学者,我正在尝试学习打字稿中的导入和导出。所以我写了下面的代码。请看一下。

我有三个文件:

 1.animal.ts  
 2.bird.ts 
 3.application.ts
Run Code Online (Sandbox Code Playgroud)

Animal.ts:

 1.animal.ts  
 2.bird.ts 
 3.application.ts
Run Code Online (Sandbox Code Playgroud)

小鸟

export class Animal {
    name:string
    age:number
    constructor(name:string,age:number){
        this.name=name;
        this.age=age
    }
    
    sleep(){
        console.log("I do sleep")
    }

    eat(){
        console.log("I do eat")
    }
}
Run Code Online (Sandbox Code Playgroud)

应用

import {Animal} from "./animal"

export class Bird extends Animal{

    constructor(name:string,age:number){
        super(name,age)
    }

    fly(){
        console.log("I can fly also")
    }
}
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?这个错误实际上意味着什么?

typescript

4
推荐指数
1
解决办法
2万
查看次数

打字稿:错误 TS2314:通用类型 'Array<T>' 需要 1 个类型参数

我正在学习打字稿,并且编写了非常基本的代码。

class School {

    nameOfStudents: Array[string];
    noOfteachers: number

    constructor(name: Array[string], no: number) {
        this.nameOfStudents = name;
        this.noOfteachers = no;
    }

    printName():void{

        for(let i=0;i<this.nameOfStudents.length;i++){
            console.log(this.nameOfStudents[i])
        }
    }
}
let arr=["a","b","c","d","e"]
let school = new School(arr,100);

school.printName();
Run Code Online (Sandbox Code Playgroud)

在我使用数组的地方,我收到以下错误:

错误 TS2314:通用类型“数组”需要 1 个类型参数我哪里做错了?

typescript

2
推荐指数
1
解决办法
9056
查看次数

Comparator.comparing在java 8流中没有Method引用时无法正常工作

List<Animal> animals = this.service.findAll();
animals = animals.stream().sorted(Comparator.comparing(Animal::getName)).collect(Collectors.toList());

//working 
Run Code Online (Sandbox Code Playgroud)

List<Animal> animals = this.service.findAll();
animals = animals.stream().sorted(Comparator.comparing(Animal.getName()).collect(Collectors.toList());

//Not working..
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我为什么我不能使用比较器比较没有方法参考?

java stream comparator java-8

-5
推荐指数
1
解决办法
830
查看次数

标签 统计

typescript ×2

comparator ×1

java ×1

java-8 ×1

stream ×1