什么意思“通用类型'功能<t>'在Typescript中需要1个类型的参数?

时间:2016-04-22 12:57:04

标签: generics typescript geojson

我尝试在打字稿中使用GeoJson,但编译器会为这两个变量抛出错误:Generic type 'Feature<T>' requires 1 type argument(s)

  const pos = <GeoJSON.Feature>{
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": [0, 1]
    }
  };

  const oldPos = <GeoJSON.Feature>{
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": [2, 4]
    }
  };

这是什么意思?

1 个答案:

答案 0 :(得分:3)

Feature接口需要一个参数:

 To use these routines:

    1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
    2) Add the following line to your .bashrc/.zshrc:
       source ~/.git-completion.bash
    3) Consider changing your PS1 to also show the current branch,
       see git-prompt.sh for details.

试试这个:

# install the bash-completion vai apg-get 
sudo apt-get install git bash-completion

也许介绍帮助类型并在pos上设置类型而不是铸造将帮助您确保设置所需的属性&#39;属性:

export interface Feature<T extends GeometryObject> extends GeoJsonObject
{
    geometry: T;
    properties: any;
    id?: string;
}