我有一个导入当前组件的汽车模型。试图将一组汽车声明为其中一个函数的返回类型。但编译器无法识别汽车阵列类型。你能帮忙吗?
carcomponent.ts
import { Car } from '../models/car';
export class carComponent implements onInit {
public car : Car;
carsavailable(): Car[] { //delcaring Car[] is not recognized.
}
}
car.ts .......
export class Car {
name: string;
}
错误
编译器用红色强调Car [],并说'一个函数,其delcared类型既不是' void'也没有任何'必须返回一个值。
我是否必须在某处插入汽车或更改返回类型声明方式。
答案 0 :(得分:2)
因为您没有从函数返回任何值,所以编译器显示错误
from concurrent.futures import ProcessPoolExecutor
import time
import random
def worker1(arg):
time.sleep(random.random())
return arg
def pipe12(future):
pool2.submit(worker2, future.result()).add_done_callback(pipe23)
def worker2(arg):
time.sleep(random.random())
return arg
def pipe23(future):
pool3.submit(worker3, future.result()).add_done_callback(spout)
def worker3(arg):
time.sleep(random.random())
return arg
def spout(future):
print(future.result())
if __name__ == "__main__":
__spec__ = None # Fix multiprocessing in Spyder's IPython
pool1 = ProcessPoolExecutor(2)
pool2 = ProcessPoolExecutor(2)
pool3 = ProcessPoolExecutor(2)
for i in range(10):
pool1.submit(worker1, i).add_done_callback(pipe12)
pool1.shutdown()
pool2.shutdown()
pool3.shutdown()
答案 1 :(得分:1)
您正在声明一个返回类型的方法,因此它应该返回一个值
carsavailable(): Car[] {
return [];
}