whitlockjc / json-refs

Various utilities for JSON Pointers (http://tools.ietf.org/html/rfc6901) and JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeScript definitions are invalid

bbqsrc opened this issue · comments

There's missing types in the returned Promises, causing my builds to fail.

node_modules/json-refs/index.d.ts:228:75 - error TS2314: Generic type 'Promise<T>' requires 1 type argument(s).

228 declare function findRefsAt(location: string, options?: JsonRefsOptions): Promise;
                                                                              ~~~~~~~


node_modules/json-refs/index.d.ts:298:77 - error TS2314: Generic type 'Promise<T>' requires 1 type argument(s).

298 declare function resolveRefs(obj: any | object, options?: JsonRefsOptions): Promise;
                                                                                ~~~~~~~


node_modules/json-refs/index.d.ts:312:78 - error TS2314: Generic type 'Promise<T>' requires 1 type argument(s).

312 declare function resolveRefsAt(location: string, options?: JsonRefsOptions): Promise;

Thanks for the heads up, I'll get it sorted.

Type for refs property of ResolvedRefsResults object is incorrect (should be a map of string to ResolvedRefDetails) and doesn't match with the documentation comment:

declare interface ResolvedRefsResults {
    /**
     * An object whose keys are JSON Pointers *(fragment version)*
     * to where the JSON Reference is defined and whose values are {@link ResolvedRefDetails}
     */
    refs: ResolvedRefDetails;
    /**
     * The array/object with its JSON References fully resolved
     */
    resolved: object;
}

Shouldn't it be?

declare interface ResolvedRefsResults {
    /**
     * An object whose keys are JSON Pointers *(fragment version)*
     * to where the JSON Reference is defined and whose values are {@link ResolvedRefDetails}
     */
    refs: { [jsonPointer: string]: ResolvedRefDetails };
    /**
     * The array/object with its JSON References fully resolved
     */
    resolved: object;
}

If you want I can open another issue. Thanks.

Yep, you're right. I need to figure out how to document that with JSDoc so these get generated properly.

This should be fixed in json-refs@v3.0.9. Do you mind verifying?

I don't think it is fixed yet (looking at index.d.ts file line# 249 @3.0.9) - the refs property is still of type ResolvedRefDetails instead of { [jsonPointer: string]: ResolvedRefDetails }

json-refs@3.0.10 should fix the validity of the TypeScript declarations but it does not describe the key/value types of the refs property. It should be fine.

I think these definitions are still wrong in 3.0.10. I'm not getting resolved for the resolveRefsAt method.

I don't understand.

resolveRefsAt returns Promise<RetrievedResolvedRefsResults> when it should be returning the same as Promise<ResolvedRefsResults>. The types are incorrect because it actually returns {resolved} and not {value}.

Do you mind creating a new issue for this? I think the overarching issues with TypeScript definitions was resolved but there is another specific issue that needs to be created.

Thank you.