Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript types are difficult to use #402

Closed
sstone1 opened this issue Mar 22, 2022 · 0 comments
Closed

TypeScript types are difficult to use #402

sstone1 opened this issue Mar 22, 2022 · 0 comments
Assignees

Comments

@sstone1
Copy link
Contributor

sstone1 commented Mar 22, 2022

The TypeScript types are generated as follows:

export var ModelManager: typeof import("./lib/modelmanager");

This means that you end up having to write verbose code to use the types:

import {
  ModelManager
} from '@accordproject/concerto-core';

// This is OK.
const modelManager = new ModelManager();

someFunc(
  // This is way too verbose!
  modelManager: InstanceType<typeof ModelManager>
): void {
  // TODO: implementation
}

The problem stems from the way they are exported from index.js:

module.exports.ModelManager = require('./lib/modelmanager');

Switching them to this pattern:

const ModelManager = require('./lib/modelmanager');

module.exports = {
    ModelManager
};

Results in more common TypeScript types:

import ModelManager = require("./lib/modelmanager");
export { ModelManager };

And easier usage of those types:

import {
  ModelManager
} from '@accordproject/concerto-core';

// This is OK.
const modelManager = new ModelManager();

someFunc(
  // This is better!
  modelManager: ModelManager
): void {
  // TODO: implementation
}
sstone1 pushed a commit to sstone1/concerto that referenced this issue Mar 22, 2022
sstone1 pushed a commit to sstone1/concerto that referenced this issue Mar 22, 2022
sstone1 pushed a commit to sstone1/concerto that referenced this issue Mar 25, 2022
sstone1 pushed a commit to sstone1/concerto that referenced this issue Mar 25, 2022
sstone1 pushed a commit to sstone1/concerto that referenced this issue Mar 25, 2022
sstone1 pushed a commit to sstone1/concerto that referenced this issue Mar 25, 2022
mttrbrts pushed a commit that referenced this issue Mar 25, 2022
) (#405)

* fix(types): typescript type generation improvements (contributes to #402)

Signed-off-by: Simon Stone <[email protected]>

* fix(types): use @type annotation suggestion from @mttrbrts

Signed-off-by: Simon Stone <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant