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 support #282

Closed
sebald opened this issue Dec 7, 2015 · 22 comments
Closed

TypeScript support #282

sebald opened this issue Dec 7, 2015 · 22 comments
Labels

Comments

@sebald
Copy link

sebald commented Dec 7, 2015

Hi there,

is it possible to use documentation with TypeScript? If not, are there any plans to support it?

@tmcw
Copy link
Member

tmcw commented Dec 7, 2015

We've started documenting Flow compatibility in GETTING_STARTED https://github.com/documentationjs/documentation/blob/master/docs/GETTING_STARTED.md#flow-type-annotations but need more TypeScript examples, as well as a bit of context for what's the overlap & difference between the two syntaxes.

The gist is that documentation.js is able to infer parameter types from Flow type annotations, so that you can omit JSDoc-style type descriptions. It can also transform typedef statements into typedefs in documentation, again with inferred property types. The technical guts of this transformation are in flow_doctrine, that translates typeAnotation AST nodes (as parsed by Babel) into type objects like doctrine would export.

@tmcw
Copy link
Member

tmcw commented Dec 10, 2015

Reading into this, we do need to make it clear that the scope is supporting TypeScript type annotations, where they overlap with Flow and not support for everything in TypeScript. Babel can't parse TypeScript, so we can't.

@tmcw
Copy link
Member

tmcw commented Dec 9, 2016

Babel listed TypeScript support in the potential future plans of their update. It's probably still a ways out, though, and as before Babel's support is necessary for documentationjs's support.

@tmcw tmcw added the upstream label Dec 9, 2016
@tmcw
Copy link
Member

tmcw commented Feb 24, 2017

I'm going to make the call to cut TypeScript support as a TODO right now. I'd be happy and overjoyed to review and accept a PR implementing support, but given the mountain of other things to work on, it isn't something I can realistically say I can do in 2017.

@tmcw tmcw closed this as completed Feb 24, 2017
@abarisain
Copy link

Hi!

Babylon supports typescript if you enable the matching plugin. It works really well: prettier's typescript support is based on it.

I'll try updating documentationjs' babylon version, and parsing settings. As I am unfamiliar with how this project works, do you think this will be enough, or would it require significant changes to code using the parser?

@arv
Copy link
Contributor

arv commented Nov 29, 2017

It depends on what AST we get. Is there an overlap between the Flow an TS AST?

@abarisain
Copy link

Unfortunately, it seems not.

They're quite different, so I guess another doctrine would be required?

Here is the partial result for a simple test class:

test.js
------
// @flow

var test: string;

class Foo {
    bar: string;

    test(arg1: string, arg2: string): string {
        return 2;
    }
}

export default Foo;

test.ts
------
// test comment

var test: string;

class Foo {
    bar: string;

    public test(arg1: string, arg2: Number): Number {
        return 2;
    }
}

export default Foo;

screen shot 2017-11-29 at 17 29 11

screen shot 2017-11-29 at 17 30 25

(This requires babylon@7.0.0beta, and you can't use the "flow" and "typscript" plugins at the same time)

@abarisain
Copy link

So, I gave it a shot and it looks like there's a lot of work figuring out what the AST looks like before getting something out.
Getting familiar with documentationjs' codebase at the same time certainly isn't helping me (not that it's bad or anything!).
I'll post an update here whenever/ifever I get something working.

I don't think that the issue should be reopened.
Thanks for the fast reply!

@Almenon
Copy link

Almenon commented Jan 23, 2018

For those looking for a typescript documentation generator there is one here.

Though even if you are using typescript you can still run documentation on your generated js file.
I just did that over at arepl-backend

@StoneCypher
Copy link

typedoc is really weak, and doesn't support almost any of what you need in a real documentation generator. can't even make public and private documentation

in the meantime typescript has mostly won, and is expected to represent es8's possible type system

@giladgray
Copy link

@tmcw what would it take to add typescript support today (generally, not specifically today)? would be very cool to use this on one of my large typescript codebases, so i'm motivated to contribute but i don't know where to start?

it seems like babylon's support for typescript may have improved, so perhaps this is worth reinvestigating.

@tmcw
Copy link
Member

tmcw commented Apr 29, 2018

Sure, that's be great! I can't be 100% of sure what's required without implementing it, but what I expect is:

  • Parse TypeScript. See src/parsers/javascript: it'd be like that, using a TypeScript-compatible parser
  • Switch to that parser when a file has a .ts extension - see src/index.js for an example of how we swap between vue & js parsers when we see a .vue extension. It'd be the same idea.
  • Translate TypeScript to doctrine expressions for types - see src/flow_doctrine.js for how we currently translate Flow annotations to doctrine.
  • Tweak the inference steps (src/infer/) for any differences between the TypeScript AST and the JavaScript AST, if there are any.

I'm not up-to-speed on step (1), whether babylon is now good at TypeScript parsing. If so - and if that's only in babylon 7, that means this task would encompass #996, the update to the Babel 7 ecosystem.

@scharf
Copy link

scharf commented May 10, 2018

TSDoc may be interesting in this context. See also Format TSDoc: A TypeScript Source Code Documentation Format.

@rdmurphy
Copy link

Now that Babel can parse Typescript via @babel/plugin-transform-typescript, I wonder if this is now closer to being possible?

@StoneCypher
Copy link

nope. all that does is strip the typescript out

@bodia-uz
Copy link
Contributor

bodia-uz commented Oct 21, 2018

@babel/plugin-transform-typescript did not parse typescript. But babylon(renamed to babel-parser), which used by babel v7 and by documentationjs, does.

@berstend
Copy link

berstend commented Feb 3, 2019

Any updates on this? :-)

Would love to migrate one of my projects to TypeScript, but most of the documentation is auto-generated using this awesome project and I don't want to loose that. 😄

Happy to help, in case there are clear deliverables to make this happen (not familiar with the documentationjs code base, yet).

Edit, just became aware of this: https://github.com/tgreyuk/typedoc-plugin-markdown
Looks promising on first glance, will test if it's an adequate replacement in my case.

@donmccurdy
Copy link

donmccurdy commented Mar 8, 2019

There's a proposed solution here: jsdoc/jsdoc#272 (comment), using jsdoc-babel and @babel/preset-typescript.

I tried typedoc+typedoc-plugin-markdown recently, and unfortunately it fails if you need compilerOptions.types, per TypeStrong/typedoc#311. That was a blocker for my project.

@DamickDoni
Copy link

soo...? any news? Does ts work now with documentationjs?

@devongovett devongovett mentioned this issue Apr 19, 2019
81 tasks
@devongovett
Copy link
Contributor

I am working on TypeScript support. See WIP PR here: #1234

@SkeLLLa
Copy link

SkeLLLa commented May 2, 2019

@devongovett great job! But are there any examples or example project where I can find how to properly use or configure the project? I've tried to use documentation just as usual npx documentation build ./src/* --resolve=node -f md, but I've received empty output.

@tmcw
Copy link
Member

tmcw commented May 4, 2019

@SkeLLLa Please open a new issue and follow the issue template, including details like the source code you're using, and whether you've added documentation comments, and so on. Please don't tag onto existing issues with vague reports.

@documentationjs documentationjs locked as off-topic and limited conversation to collaborators May 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests