diff --git a/types/meteor-mdg-validated-method/index.d.ts b/types/meteor-mdg-validated-method/index.d.ts index 0b568177fe..ece3594af6 100644 --- a/types/meteor-mdg-validated-method/index.d.ts +++ b/types/meteor-mdg-validated-method/index.d.ts @@ -17,6 +17,40 @@ declare module 'meteor/mdg:validated-method' { export type ValidatedMethodArg = T extends ValidatedMethod ? Argument : never; export type ValidatedMethodReturn = T extends ValidatedMethod ? Return : never; + export interface ValidatedMethodThisBase { + /** + * @summary Access inside a method invocation. Boolean value, true if this invocation is a stub. + * @locus Anywhere + */ + isSimulation: boolean; + /** + * @summary Call inside a method invocation. Allow subsequent method from this client to begin running in a new fiber. + * @locus Server + */ + unblock(): void; + /** + * @summary The id of the user that made this method call, or `null` if no user was logged in. + * @locus Anywhere + */ + userId: string | null; + /** + * @summary Set the logged in user. + * @locus Server + * @param userId The value that should be returned by `userId` on this connection. + */ + setUserId(userId: string | null): void; + /** + * @summary Access inside a method invocation. The [connection](#meteor_onconnection) that this method was received on. `null` if the method is not associated with a connection, eg. a server + * initiated method call. Calls to methods made from a server method which was in turn initiated from the client share the same `connection`. + * @locus Server + */ + connection: Meteor.Connection; + /** + * @summary The seed for randomStream value generation + */ + randomSeed(): string; + } + /** * When declaring a mixin that adds fields to ValidatedMethodOptions, augment this to add them */ @@ -71,7 +105,7 @@ declare module 'meteor/mdg:validated-method' { > = TOptions extends ValidatedMethodOptions ? Argument : never; export class ValidatedMethod any> { - constructor(options: ValidatedMethodOptionsWithMixins); + constructor(options: ValidatedMethodOptionsWithMixins & ThisType); call: Argument extends NoArguments ? // methods with no argument can be called with () or just a callback ((unusedArg: any, callback: (error: Meteor.Error, result: Return) => void) => void) & diff --git a/types/meteor-mdg-validated-method/meteor-mdg-validated-method-tests.ts b/types/meteor-mdg-validated-method/meteor-mdg-validated-method-tests.ts index 32fd53166a..cfed840e7f 100644 --- a/types/meteor-mdg-validated-method/meteor-mdg-validated-method-tests.ts +++ b/types/meteor-mdg-validated-method/meteor-mdg-validated-method-tests.ts @@ -201,7 +201,27 @@ new ValidatedMethod({ }); // method can access its name -// TODO "slice" call is needed here because this method actually returns `Return<() => TName> & string` and I don't know why -// (the `& string` was something I added so you can at least use the name in weird situations like this, but I don't get why TName isn't getting resolved there - it's clearly known by now!) -// $ExpectType string -methodReturnsName.call().slice(); +// $ExpectType "methodReturnsName" +methodReturnsName.call(); + +// method has all expected "this" properties +new ValidatedMethod({ + name: 'methodThatUsesThis', + validate: null, + run() { + // $ExpectType "methodThatUsesThis" + this.name; + // $ExpectType boolean + this.isSimulation; + // $ExpectType string | null + this.userId; + // $ExpectType void + this.setUserId("test"); + // $ExpectType Connection + this.connection; + // $ExpectType string + this.randomSeed(); + // $ExpectType void + this.unblock(); + } +});