Skip to content

Commit

Permalink
feat: Optional promise on init
Browse files Browse the repository at this point in the history
  • Loading branch information
nesvet committed Sep 1, 2024
1 parent 2111f8c commit bbd9552
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/InSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ export class InSite<AS extends AbilitiesSchema, O extends Options<AS>> extends E
}


static init<IO extends Options<any>>(options: IO) {
type IAS = IO extends Options<infer EIAS> ? EIAS : never;

return (new InSite(options)).whenReady() as Promise<InSiteWithActualProps<InSite<IAS, IO>, IO>>;
static init<IO extends Options<any>, IAS extends AbilitiesSchema = IO extends Options<infer A> ? A : never>(options: IO, asPromise: true): Promise<InSiteWithActualProps<InSite<IAS, IO>, IO>>;
static init<IO extends Options<any>, IAS extends AbilitiesSchema = IO extends Options<infer A> ? A : never>(options: IO, asPromise?: false): InSiteWithActualProps<InSite<IAS, IO>, IO>;
static init<IO extends Options<any>, IAS extends AbilitiesSchema = IO extends Options<infer A> ? A : never>(options: IO, asPromise = false) {
const inSite = new InSite(options);

return asPromise ?
inSite.whenReady() as Promise<InSiteWithActualProps<InSite<IAS, IO>, IO>> :
inSite as InSiteWithActualProps<InSite<IAS, IO>, IO>;
}

}

0 comments on commit bbd9552

Please sign in to comment.