B
B
BonBon Slick2020-07-19 09:02:44
typescript
BonBon Slick, 2020-07-19 09:02:44

Why does objectB Instanceof InterfaceA return only refers to a type, but is being used as a value here?

/**
   * Reference: https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiauth2authorizeresponse
   */
  interface AuthorizeResponse {
    access_token: string;
    id_token: string;
    code: string;
    scope: string;
    expires_in: number;
    first_issued_at: number;
    expires_at: number;
    error: string;
    error_subtype: string;
  }

gAuthenticate(): void {
        gapi.auth2.authorize(this.gapiConfig, response => {
            if (response.error || response instanceof AuthorizeResponse) {


TS2693: 'AuthorizeResponse' only refers to a type, but is being used as a value here.


Google Auth API Docs

TS @type/gapi GIT repository

According to TS Docs


But in practice instanceof in TS

Why doesn't instanceof work?
Answer on Stack is the only valid comparison option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2020-07-19
@BonBonSlick

Because instanceof works at runtime when there is no typescript anymore, and by and large only with classes.
So the SO answer is the only way. Official documentation https://www.typescriptlang.org/docs/handbook/advan...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question