Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserModel {
- constructor(opt) {
- if (opt.id) {
- }
- }
- get name() {
- return 'Prozacgod'
- }
- get rank() {
- return 'god';
- }
- }
- interface IUser {
- name: string;
- };
- interface IModels {
- UserModel: UserModel;
- }
- interface IApiContext {
- // this would be the current logged in user
- user: IUser;
- models: IModels;
- };
- // In my code these api calls are isolated through a native JS library, so typeings get lost
- // I need models to be in the ctx argument
- let api = {
- logUser(ctx:IApiContext) {
- console.log(ctx.user.name);
- },
- getUser(ctx:IApiContext, id:number) {
- return new ctx.models.UserModel({id});
- }
- };
- function fakeCallApiFunction() {
- // declare the ctx the code is called with
- var ctx: IApiContext = {
- user: {name:'Prozacgod'},
- models: {
- UserModel
- }
- };
- api.logUser(ctx);
- let user = api.getUser(ctx, 1);
- console.log(`${user.name} <${user.rank}>`);
- }
- fakeCallApiFunction();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement