Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Revisit Mixin implementation when TypeScript 2.8 is released #118

Open
etsuo opened this issue Jan 11, 2018 · 0 comments
Open

Revisit Mixin implementation when TypeScript 2.8 is released #118

etsuo opened this issue Jan 11, 2018 · 0 comments

Comments

@etsuo
Copy link
Member

etsuo commented Jan 11, 2018

Right now, using SapiModelMixin requires quite a bit of typing tapdancing:

import {
  Db,
  IDbGetParams,
  IFromDbOptions,
  Json,
  Model,
  SakuraApi,
  SapiModelMixin
}            from '@sakuraapi/api';
import {
  Collection,
  CollectionInsertOneOptions,
  CollectionOptions,
  Cursor,
  Db as MongoDb,
  DeleteWriteOpResultObject,
  InsertOneWriteOpResult,
  ObjectID,
  ReplaceOneOptions,
  UpdateWriteOpResult
}            from 'mongodb';
import {dbs} from '../config/db';

export {
  Collection,
  CollectionInsertOneOptions,
  CollectionOptions,
  Cursor,
  MongoDb,
  DeleteWriteOpResultObject,
  InsertOneWriteOpResult,
  ObjectID,
  ReplaceOneOptions,
  UpdateWriteOpResult,
  IDbGetParams,
  IFromDbOptions,
  SakuraApi
};

@Model({
  dbConfig: dbs.user
})
export class User extends SapiModelMixin() {
}

See here to get a better understanding as to why all these exports are currently necessary.

The same applies to SapiInjectableMixin and SapiRoutableMixin, but to a lesser extent.

This translates to a fairly unideal developer experience (DX). To mitigate that for the moment, sapi cli will implement (generators)[https://github.com/sakuraapi/cli/issues/10] for @Model, @Routable and @Injectable to get automate inclusion of the necessary exports. Check back in with: microsoft/TypeScript#9944 when TypeScript 2.8 is released to see if there's a less tedious way to handle this in the future.

Also, see if the TypeScript community suddenly decided to allow static members for interfaces, because that would be a better alternative seeing as these mixins don't actually do anything other than define types that are injected by various decorators (@Model, @Routable, @Injectable).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant