小编Ala*_*air的帖子

TypeScript错误TS2339,但属性确实存在

当我使用gulp编译以下TypeScript代码时,我得到:错误TS2339:类型'Response'上不存在属性'accessToken'.在Visual Studio 2015年ErrorList窗口报告了同样的错误的data.accessTokendata.expiryDate.当我注释掉引用变量的两行时data,代码运行并且调试器显示data不是"响应"类型,并且实际上包含属性data.accessTokendata.expiryDate.在Visual Studio中,当我将鼠标悬停在该data变量,则提示正确地报告的类型dataany.

为什么TypeScript无法正确转换,我该如何解决这个问题呢?为什么TypeScript认为data是类型Response而不是类型any?我正在使用TypeScript 2.1.4.http.fetch使用此处记录的 aurelia fetch客户端

/// <reference path="../typings/index.d.ts" />
import 'fetch';
import {HttpClient, json} from 'aurelia-fetch-client';
import {inject} from 'aurelia-framework';
import {BearerToken} from './common/bearer-token';
export class ApiToken
{
...
    public refreshToken(): Promise<BearerToken>
    {
        let token: BearerToken = new BearerToken();
        token.accessToken = "no_data";
        token.expiryDate = Date.now();

        return this.http.fetch('/Account/getToken')
            .then(response => response.json())
            .then(data => …
Run Code Online (Sandbox Code Playgroud)

typescript2.0

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

标签 统计

typescript2.0 ×1