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

Programmatic API #37

Closed
sheerun opened this issue Sep 20, 2019 · 9 comments
Closed

Programmatic API #37

sheerun opened this issue Sep 20, 2019 · 9 comments

Comments

@sheerun
Copy link

sheerun commented Sep 20, 2019

Hello and thank you for creating this!

A programmatic API would be useful so one can use it as part of e.g. Jest or AVA test suite without running separate binary for this and allowing for easy watch mode. API could look something like:

const tsd = require('tsd')

it('has correct type definitions', async () => {
  await tsd()
})

And tsd could raise an exception if issues are found

@SamVerschueren
Copy link
Collaborator

Instead of throwing, it might be more useful if it returned the list of errors? Then you can verify that it has none or do something else with them?

@sheerun
Copy link
Author

sheerun commented Sep 27, 2019

also fine

@harrysolovay
Copy link

I agree this would be very useful. Even more so if usage was possible from the tsd-executing file:

import { expectType } from "tsd";

interface Person {
  name: string;
  friends: Person[];
}

const personA = {
  name: "Joe",
  friends: [personB],
};

const personB = {
  name: "Jack",
  friends: [personA],
};

try {
  expectType<Person>(personA);
} catch(e) {}

Internally, expectType would get its parent module path (the file from which it is executed) and add it to a shared program instance. The rest of the work––it seems––is already done. This feature would be invaluable to a project on which I'm currently working. @SamVerschueren –– any chance you see this as a good addition to the API?

@SamVerschueren
Copy link
Collaborator

@harrysolovay Could you create a new issue so we can discuss it separately? I feel these are two separate use cases and before I decide if we should add it, I want to discuss things as to why it would be useful.

@SamVerschueren
Copy link
Collaborator

@sheerun Added it. Will let you know when it's released. I actually want to fix this #39 as well in the next release.

@harrysolovay
Copy link

@SamVerschueren thank you! I'm opening the new issue right now 💯

@Aqzhyi
Copy link

Aqzhyi commented Oct 22, 2019

hi, hello, @SamVerschueren

seems this issue is close/done/finish/stable (?) and already have readme wrote at master

but await tsd() got This expression is not callable. has no call signatures at 0.9.0

may you make a dist-tag on npm? 0.10.0 or 0.9.0-beta or etc?

npm info tsd

dist-tags:
beta.2: 0.6.5-beta.2  beta: 0.6.5-beta      latest: 0.9.0         next: 0.6.0-beta.5

published 3 weeks ago

@SamVerschueren
Copy link
Collaborator

I wanted to ship something else in the new release as well but need more time to think some things through. Will make a new release this afternoon.

@SamVerschueren
Copy link
Collaborator

This feature is shipped in v0.10.0 🎉

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

4 participants