Search code examples
typescripttypescript2.0oidc-client-js

Cannot find name when using the constructor but can when casting


I have imported two types.

import { UserManager, WebStorageStateStore } from "oidc-client";

From looking at the source, both of these are classes with constructors. I can all the constructor of the first, and can cast with the second, but I cannot call the constructor of the second.

Both of these work.

let um = new UserManager({});
let w1 = <WebStorageStateStore> {};

TypeScript complains about this one. "Cannot find name 'WebStorageStateStore'".

let w2 = new WebStorageStateStore();

Why cannot TypeScript find the constructor when it is able to cast to the type?

This is the source for oidc-client.


Solution

  • TypeScript complains about this one. "Cannot find name 'WebStorageStateStore'".

    Just because a variable exists in the type declaration space doesn't mean its also in the variable declaration space. In your case its only in the type space.

    More

    Declaration spaces are covered here https://basarat.gitbooks.io/typescript/content/docs/project/declarationspaces.html