Skip to content

chore: support typescript - #117

Open
moshfeu wants to merge 1 commit into
mokkabonna:masterfrom
moshfeu:chore/support-typescript
Open

chore: support typescript#117
moshfeu wants to merge 1 commit into
mokkabonna:masterfrom
moshfeu:chore/support-typescript

Conversation

@moshfeu

@moshfeu moshfeu commented Oct 10, 2020

Copy link
Copy Markdown

If I understand the API correctly.
Also, I'm not that expert with TypeScript but this is working for me locally. If anyone else who knows typescript can review it, that will be great.

resolve #107

@alma3lol

alma3lol commented Jan 1, 2021

Copy link
Copy Markdown

Please someone merge this!

@prkirby

prkirby commented Jan 28, 2022

Copy link
Copy Markdown

Bumpppppp

@c-vetter c-vetter left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moshfeu
Thanks for the PR, I've reviewed it. This needs some work, please see my comments.
I'd like to help out beyond reviewing, but don't have the time right now.

Comment thread README.md
{
"compilerOptions": {
"types": [
"inquirer-autocomplete-prompt"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this change. See the docs:

If types is specified, only packages listed will be included in the global scope. For instance:

Besides, "types": "index.d.ts", in package.json already provides the types.

Comment thread index.d.ts
export interface QuestionMap<T extends Answers = Answers> {
autocomplete: AutocompleteQuestion<T>;
}
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind the final newline 😉 It's better for the diffs.

Comment thread index.d.ts
@@ -0,0 +1,22 @@
import inquirer, { Answers } from 'inquirer';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is, I get this error when trying your branch:

error TS2345: Argument of type 'typeof import("./node_modules/inquirer-autocomplete-prompt/index")' is not assignable to parameter of type 'PromptConstructor'.
  Type 'typeof import("./node_modules/inquirer-autocomplete-prompt/index")' provides no match for the signature 'new (question: any, readLine: Interface, answers: Answers): PromptBase'.

10 inquirer.registerPrompt(`autocomplete`, autocomplete)

This is my tsconfig.json:

{
	"extends": "@tsconfig/node12/tsconfig.json",
	"compilerOptions": {
		"esModuleInterop": true,
		"moduleResolution": "node",
		"strict": true,
		"outDir": "./.transpiled",
		"noUncheckedIndexedAccess": true,
		"noPropertyAccessFromIndexSignature": true,
	},
	"include": [ "./" ],
}

It seems to me that this file is missing the actual export types, please verify and fix.


export default interface InquirerAutocompletePrompt {}

declare var inquirerAutocompletePrompt: InquirerAutocompletePrompt;
export = inquirerAutocompletePrompt;

I added that 👆 to the end of this file and the error changed to this 👇

error TS2345: Argument of type 'InquirerAutocompletePrompt' is not assignable to parameter of type 'PromptConstructor'.  
  Type 'InquirerAutocompletePrompt' provides no match for the signature 'new (question: any, readLine: Interface, answers: Answers): PromptBase'.

10 inquirer.registerPrompt(`autocomplete`, autocomplete)

Note how typeof import("./node_modules/inquirer-autocomplete-prompt/index") changed to InquirerAutocompletePrompt – that seems to confirm my suspicion.

Comment thread index.d.ts
@@ -0,0 +1,22 @@
import inquirer, { Answers } from 'inquirer';

declare module 'inquirer' {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To extend the inquirer interfaces, this seems more appropriate to get alignment:

Suggested change
declare module 'inquirer' {
declare namespace inquirer {

See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/inquirer/index.d.ts#L95

Note: So far, I have not typed across packages myself, so I may be missing something. This comment is really based only on my observation in @types/inquirer.

@ipatalas

ipatalas commented Jan 5, 2023

Copy link
Copy Markdown

Hi guys, @jayeeson made pretty nice typings in here: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/inquirer-autocomplete-prompt

If there is a will on both sides (@jayeeson and maintainers here) I can spend some time bringing those typings here. Already did a quick proof of concept and seems to work. The typings themselves needs a bit of love to support everything but I'll hold off for now until we have some agreement here.

@jayeeson

jayeeson commented Jan 6, 2023

Copy link
Copy Markdown

The typings are probably a little outdated but it's a small package. What's the motivation to bring the types in here, if you want TS support just add the DefinitelyTyped package

@ipatalas

ipatalas commented Jan 6, 2023

Copy link
Copy Markdown

Now I'm having second thoughts. All other inquirer plugins (+ the lib itself) have typings in DefinitelyTyped so it doesn't make sense to break this consistency and I definitely don't want to move them all :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typescript support?

7 participants