什么'无效'打字稿是什么意思?

时间:2015-10-31 07:50:07

标签: javascript typescript

所以我遇到了在线,我想知道void在打字稿中有什么意义?

就像这里:

private _handleProjectQuerySuccess(data: IProject[]): void  
{
    data.sort(this._projectSort);

    var pathname = this._$location.path();

    var activeSet = false;
    data.forEach((project: IProject) =>
    {
        project.active = pathname == '/' + project.id;
        activeSet      = activeSet || project.active;

        project.name        = this._$sanitize(project.name);
        project.description = this._$sanitize(project.description);
        project.url         = this._$sce.trustAsUrl(project.url);
        project.readme      = this._$sce.trustAsHtml(project.readme);

        project.title = project.name + (project.fork ? ' (fork)' : ' (repo)');

        this._scope.projects.push(project);

        this._projectMap[project.id] = this._scope.projects[this._scope.projects.length - 1];
    });

    if (!activeSet)
    {
        data[0].active = true;
    }
}

在我们宣布私有后,我们暗示 void ......这是什么意思?

2 个答案:

答案 0 :(得分:16)

这只是一种类型,如下所示:

Void

  

或许在某些方面与“任何”相反。如果没有任何类型,那就是“无效”。您通常会将此视为不返回值的函数的返回类型:

Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_KTKRegion", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_KTKLocationManager", referenced from:
      objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

答案 1 :(得分:0)

请注意, void any 类型有些重叠,起初可能很奇怪。虽然 void 可能不返回任何数据(仅null和undefined)-任何都可能返回任何类型的数据(包括null和undefined)。