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

Typings #59

Open
Rich-Harris opened this issue Aug 29, 2017 · 7 comments
Open

Typings #59

Rich-Harris opened this issue Aug 29, 2017 · 7 comments

Comments

@Rich-Harris
Copy link
Contributor

I have become utterly spoiled by TypeScript, and desperately miss libraries that don't have type declarations.

Short demo of what using indian-ocean would be like with types (note: this is in a JavaScript file, not a TypeScript file, in VSCode):

types

On line 6, it knows that readCsvSync is one of the methods available, so we get fuzzy autocomplete. If we got the signature wrong (i.e. first argument isn't a string) it would tell us about it. On line 8, it knows that csv is an array, so we get fuzzy autocomplete for forEach. On line 9, it knows that the value of raw.foo is a string, so we get fuzzy autocomplete for startsWith.

That was all made possible by adding a file called node_modules/indian-ocean/index.d.ts:

interface Datum {
  [key: string]: string;
}

export function readCsvSync (path: string): Datum[];

We'd basically just need to add a bunch of those for all the different readers etc. It doesn't even need to be perfect first time, as TypeScript is fairly forgiving (it'll never prevent anything from running, just might give you some red squiggles).

Whaddaya think?

@mhkeller
Copy link
Owner

Sounds great! csv soundsystem project?

Is there a way to roll this into the generated documentation too? The last bit of work I have on the rollup/es6 branch is to fix the doc generator that was broken by breaking things out into multiple files.

@Rich-Harris
Copy link
Contributor Author

my thoughts exactly! tbd whether i'll make it tonight. not sure what the docs story is. I feel like it ought to be possible to do at least what JSDocs can do from typings, but really not sure.

@mhkeller
Copy link
Owner

mhkeller commented Sep 1, 2017

Something like this? http://typedoc.org/guides/installation/

@Rich-Harris
Copy link
Contributor Author

oh, interesting. worth trying for sure

@mhkeller
Copy link
Owner

mhkeller commented Sep 8, 2017

After looking into it, I'm not super impressed with typedoc. Let's stick with documentationjs for now since it's got all the examples and things. I got it mostly working today pending some minor investigation into a change.

On this topic, declarations have begun to be merged so we'll just keep on adding them to the rollup branch (more aptly named would be 3.0.0 branch) but, as you said, they don't need to be complete before this gets merged to master.

@mhkeller
Copy link
Owner

FYI what has been implemented so far is now available in 3.0.0.

@mhkeller
Copy link
Owner

FYI#2, after some investigation, this also works in Sublime Text with the Typscript plugin. You have to set the syntax to Typescript though, which is easier with the help of this project-specific syntax plugin.

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

No branches or pull requests

2 participants