如果一个人有一个函数数组,其中一个函数的输出是下一个函数的输入,即输入和输出类型必须对齐,但可能不同对。如何使类型记录编译器能够理解类型:
type A = () => string
type B = (str: string)=> number
type C = (num: number)=> [number,number]
const a:A = ()=>'1'
const b:B = (str)=>parseInt(str)
const c:C = (num)=>[num,num]
//typescript is fine with
我目前正在开发一个Angular 2应用程序。在开发过程中,我开始使用TypeScript类从JSON创建对象,这些对象是我通过HTTP接收的,或者在表单中创建新对象时使用的。
例如,这个类可能看起来像这样。
export class Product {
public id: number;
public name: string;
public description: string;
public price: number;
private _imageId: number;
private _imageUrl: string;