문제

When calling a .NET OAuthToken Endpoint the result contains two properties starting with a ".":

{   
    "access_token":"abcde..."
    "expires_in":1209599
    ".expires":"Fri, 16 May 2014..."    <- this
    ".issued":"Fri, 02 May 2014..."     <- this
    ... more properties ...
}

What I like to do is create an interface in TypeScript to handle this result. However I do not know how to declare these two properties with the little dot in front.

export interface Token {
    access_token: string;
    expires_in: number;
    .expires???
    .issued???
}

Any idea?

도움이 되었습니까?

해결책

Viewing section 3.7.1 of the TypeScript language specification, it looks like property signatures in object literals work about the same as object literal property definitions in JavaScript, meaning a property name can be an identifier, a string literal, or a numeric literal. In other words, you can simply do:

export interface Token {
    access_token: string;
    expires_in: number;
    ".expires": string;
    ".issued": string;
}

다른 팁

Just use quoted interface members :

interface Token {
    access_token: string;
    expires_in: number;
    '.expires': number;
}

var foo:Token;
foo['.expires'] = '123'; // Error 
foo['.expires'] = 123; // okay 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top