Closed davewasmer closed 6 years ago
Does it work if this package's name changes to something without .ts
in it (i.e., jsonapi-ts
)?
I think we'd also have to change it so it didn't use namespace
, but instead simply exported everything that's top level in the current namespace as a top level export of the module itself. Then you'd do something like this to get the namespace-like references:
import * as JSONAPI from 'jsonapi-ts';
Or if you wanted only one interface:
import { Meta as JSONAPIMeta } from 'jsonapi-ts';
AFAIK nobody depends on this yet except me, so I'm willing to change it around. I like this a bit better than the current setup anyway, and we can use it for @types/ember-data
more easily too.
Not sure if I'll get to it this week (tests will have to be adjusted, etc...) but we'll have to treat https://github.com/mike-north/json-typescript the same way. Here's a quick and dirty index.ts
that works for me
// tslint:disable-next-line:array-type
type Arr<T> = Array<T>;
// tslint:disable-next-line:no-namespace
namespace JSON {
export type Primitive = string | number | boolean | null;
export interface Object {
[member: string]: Value;
}
export interface Array extends Arr<Value> {}
// tslint:disable-next-line:array-type
export type Value = Primitive | Object | Array;
}
export = JSON;
Awesome - happy to make some PRs here too. I basically have a less-complete version of this in https://github.com/denali-js/denali/blob/master/lib/render/json-api.ts right now, and would love to extract / off-load to a separate package since it seems potentially useful for Denali consumers as well as others.
Do you want to stick with using namespace
for now? From the little I've seen, it seems like namespace
s tend to eschewed in favor of modules in Typescript. I'm basing that off very little data and gut feels mostly though, so happy to stick with 'em if you'd prefer.
For reference, here's how I'd imagine your snippet above done via modules:
// tslint:disable-next-line:array-type
type Arr<T> = Array<T>;
export type Primitive = string | number | boolean | null;
export interface Object {
[member: string]: Value;
}
export interface Array extends Arr<Value> {}
// tslint:disable-next-line:array-type
export type Value = Primitive | Object | Array;
}
yeah, a namespace-free implementation would be fine, as long as namespace imports continue to work
Just curious if there is a way to use these types via direct import rather than relying on
typeRoots
and global namespaces? Something like:The above doesn't work because Typescript doesn't allow for imports ending in
.ts
;