indian-ocean icon indicating copy to clipboard operation
indian-ocean copied to clipboard

Typings

Open Rich-Harris opened this issue 7 years ago • 7 comments

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?

Rich-Harris avatar Aug 29 '17 17:08 Rich-Harris

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.

mhkeller avatar Aug 29 '17 20:08 mhkeller

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.

Rich-Harris avatar Aug 29 '17 21:08 Rich-Harris

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

mhkeller avatar Sep 01 '17 01:09 mhkeller

oh, interesting. worth trying for sure

Rich-Harris avatar Sep 01 '17 11:09 Rich-Harris

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 avatar Sep 08 '17 05:09 mhkeller

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

mhkeller avatar Oct 11 '17 06:10 mhkeller

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.

mhkeller avatar Oct 15 '17 22:10 mhkeller