Provide better Typescript definition files
See original GitHub issueHi Prismic folks 😃
I’m trying to use the nodejs package with its bundled d.ts files. However, types are not properly imported when using the module. It comes from several facts:
- First, this comes from the way the module is declared, ie. using a namespace.
declare namespace Prismic {...}
&export = Prismic;
. Only what is in the namespace is visible if i’m not mistaken. - As a library, the barel file (index.d.ts) should re-export all public APIs. When fetching the api object with
Prismic.getApi(...)
, I cannot write the proper response type since thePrismicApi
type is hidden in the namespace.
It could be better to change the namespace to a plain object while re-exporting all sub modules. This way, both the Prismic object and all APIs are visible.
Last but not the least, a little quote from the TS documentation :
Exporting a namespace from your module is an example of adding too many layers of nesting. While namespaces sometime have their uses, they add an extra level of indirection when using modules. This can quickly become a pain point for users, and is usually unnecessary.
What do you guys think ?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:19
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Documentation - Type Declarations - TypeScript
A declaration file provides a way to declare the existence of some types or values ... We'll learn more about how to write...
Read more >A quick introduction to “Type Declaration” files and adding ...
In this lesson, we are going to take a closer look at type declaration files which are one of the key ingredients of...
Read more >Generating TypeScript definition files directly from the source
Try npm install @types/pied-piper__compress , this will try to get the types from DefinitelyTyped. · Manually write the type definitions.
Read more >Generating TypeScript Definition Files from JavaScript
Write your code in JS and apply JSDoc where needed · Use the forked TypeScript npm i -D typescript-temporary-fork-for-jsdoc · Have a tsconfig....
Read more >How to create your own TypeScript type definition files (.d.ts ...
Identify imports and exports of a given module. · Identify types of the exported function (arguments and return). · Create initial .d.ts file....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Unfortunately this is still open. I guess the issue could be resolved for many of us if
d.ts/index.d.ts
would also export the other parts of the declaration files, for exampleResolvedApi.d.ts
.Now with Angular 9, the compiler issues a warning about the deep import paths, for example here: https://github.com/exportarts/ngx-prismic/issues/109.
I wonder if there is even still the need for separate
d.ts
files since the project is written in typescript anyway (see #69). What do you think?with typescript > 2.8 this should work