-
-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export types from index.d.ts #252
base: master
Are you sure you want to change the base?
Conversation
This is a BREAKING CHANGE for TypeScript which allows export of types.
I'm curious about why we changed to use default export/import instead of namespace. |
First, this is to allow exporting types at the root level. Second, this makes the imports more idiomatic with ESM imports: Third, this brings it more inline with the actual JavaScript. The default export is a class. In TypeScript namespaces solve a few problems, mostly legacy that Enquirer doesn't suffer from:
Enquirer does not fall into any of these categories. By moving away from the namespace in .d.ts -- the definitions start to look more like what they would be if Enquirer were written in TypeScript -- and the .d.ts were generated at build time. When using a namespace as a single Example: If this is approach is acceptable, it can be expanded then to export other types:
|
The default export is not a good idea because the JavaScript is still in commonJs. Using the |
The point of this PR is not to use You cannot have multiple exports when you use The purpose of this PR is to allow idiomatic type exports, which cannot be exported when |
That is not true. You can do it with In fact, I believe that is a better way to organize the types. The bottom line thou, is that the typings should stay true to the code. If you define your typings to be const enquirer = require('enquirer')
// typings indicates this is Enquirer class but in runtime it is undefined
enquirer.default This will break many JavaScript users because TypeScript language server is used to power JavaScript in IDE such as VS Code. |
This is a BREAKING CHANGE for TypeScript which allows export of types.
Where in TypeScript users would use,
import * as Enquirer from 'enquirer';
they would now do:
import Enquirer from 'enquirer';
This PR adds exporting of the
PromptOptions
type so that developers can type check objects before passing them toprompt(..)
let question: PromptOptions = { name: 'test', type: 'text', message: '' };
More individual types can be exported if this approach is approved, as it would be beneficial for TypeSrcript devs.
This PR also exports the
prompt(..)
function to allow idiomatic importimport { prompt } from 'enquirer';
of prompt.