jsigbiz / spec

JavaScript signature notation
130 stars 6 forks source link

namespacing types from multiple npm modules #12

Closed Raynos closed 10 years ago

Raynos commented 11 years ago
type Client := {
        Continuable<mongodb/Db>,
        close: Continuable<void>,
        collection: (name: String) => coll: <SNIP>
}

I have some conflict in my continuable-mongo where I'm trying to define types for Collection and Client but the underlying mongodb driver already has types for Db / MongoClient / Collection

So I want a way to solve this ambigious-ness by namespacing the types and prefixing them with the npm package.

I'm not sure whether the / delimiter is best.

Maybe also use quotes

type Client := {
        Continuable<"mongodb/Db">,
        close: Continuable<void>,
        collection: (name: String) => coll: <SNIP>
}
junosuarez commented 11 years ago

Oh, no - but then we end up with cross-module interface dependencies, which themselves can (should) be versioned.

In-scope, I think it makes the most sense, for example, to alias eg "mongodb/Db" to something like type MongoDb. This makes it more obvious that you're depending on the interface, rather than the implementation. In theory, if your module requires something that looks like the mongodb Db interface, I should be able to create some other object which has the same interface and it would be consumable by your module.

It would be convenient to have a way to cite interfaces from a concrete module. In minq, I do this by linking to the description of the interface in the other module's documentation. In my case, I think it achieves an adequate trade off of clarity vs explicitness, although it's not readily machine parseable.

For tooling, you would want a local definition of the interface in any case. If more people adopt jsig, it would be possible to have a standard way to publish and share type definitions, perhaps like https://github.com/borisyankov/DefinitelyTyped

Raynos commented 10 years ago

This is solved with import syntax.