Skip to content

Commit

Permalink
Fixed App constructor type
Browse files Browse the repository at this point in the history
  • Loading branch information
Kræn Hansen committed Jun 24, 2020
1 parent 2a85c6a commit 5c68a02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
6 changes: 2 additions & 4 deletions packages/realm-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { App } from "./App";
const appCache: { [id: string]: Realm.App } = {};

/**
* Get or create a Realm App from an id.
* Get or create a singleton Realm App from an id.
*
* @param id The Realm App id visible from the MongoDB Realm UI or a configuration
* @returns The Realm App instance. Calling this function multiple times with the same id will return the same instance.
Expand All @@ -30,9 +30,7 @@ export function app(id: string) {
if (id in appCache) {
return appCache[id];
} else {
// Ensures the App has the correct constructor type signature
const AppConstructor: Realm.AppConstructor = App;
const instance = new AppConstructor(id);
const instance = new App(id);
appCache[id] = instance;
return instance;
}
Expand Down
15 changes: 6 additions & 9 deletions types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,16 @@ declare namespace Realm {
// TODO: Add providerCapabilities?
}

/**
* The constructor of MongoDB Realm App.
*/
type AppConstructor = new <
FunctionsFactoryType extends object = DefaultFunctionsFactory
>(
idOrConfiguration: string | AppConfiguration,
) => App<FunctionsFactoryType>;

/**
* A MongoDB Realm App.
*/
class App<FunctionsFactoryType extends object = DefaultFunctionsFactory, CustomDataType extends object = any> {
/**
* Construct a MongoDB Realm App.
*
* @param idOrConfiguration The id string or configuration for the app.
*/
constructor(idOrConfiguration: string | AppConfiguration);

/**
*
Expand Down

0 comments on commit 5c68a02

Please sign in to comment.