Skip to content

Typings wrong, leads to problem starting with Typescript version 4.8.3 and Node module resolution Node16 or NodeNext #2070

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
gunters63 opened this issue Sep 16, 2022 · 11 comments
Assignees
Labels
💥 Bug Something isn't working

Comments

@gunters63
Copy link

React-simple-keyboard version
3.4.199 or newer

Describe the bug

import { default as Keyboard } from 'react-simple-keyboard'; 

does not work anymore with Typescript 4.8.3 with error:

JSX element type 'Keyboard' does not have any construct or call signatures.ts(2604)

Maybe this only happens when you import react-simple-keyboard in a project where module: "EsNext" is set.

Explanation here: microsoft/TypeScript#50690

@hodgef hodgef added the ⛔️ Cannot repro The maintainer has not been able to reproduce the issue. label Sep 17, 2022
@hodgef
Copy link
Owner

hodgef commented Sep 17, 2022

Hey @gunters63,

I don't see any issues when using a fresh create-react-app project:

image

image

image

Personally, I have never used default as .... In the react-simple-keyboard demos it's always import Keyboard ....

Regards,
Francisco Hodge

@hodgef hodgef closed this as completed Sep 17, 2022
@hodgef
Copy link
Owner

hodgef commented Sep 18, 2022

It seems to work even with the import style that you're using (default as ...):

image

Try to repro with a fresh project and if it works, compare that project to yours to see where the issue is.

@gunters63
Copy link
Author

gunters63 commented Sep 21, 2022

Hi @hodgef ,

I tried to reproduce the error with a minimal create-react-app, like you.

The error happens only when you use moduleResolution Node16 or NodeNext in tsconfig,json.

You will have to change some imports for this of course, like: import App from './App.js';

react-simple-keyboard is not the only npm package bitten by this. See again: microsoft/TypeScript#50690

I changed the issue title now accordingly.

@gunters63 gunters63 changed the title Typings wrong, leads to problem starting with Typescript version 4.8.3 Typings wrong, leads to problem starting with Typescript version 4.8.3 and Node module resolution Node16 or NodeNext Sep 21, 2022
@gunters63
Copy link
Author

I can try to fix this problem and create a PR?

@gunters63
Copy link
Author

image

@gunters63
Copy link
Author

image

@hodgef hodgef reopened this Sep 22, 2022
@hodgef hodgef added 🔍 Investigating Investigating what's causing the issue and removed ⛔️ Cannot repro The maintainer has not been able to reproduce the issue. labels Sep 22, 2022
@hodgef
Copy link
Owner

hodgef commented Sep 22, 2022

Thanks for the details @gunters63. I will look into this, but if you have a repro to share or a PR fix that we can use it will definitely be welcomed. I will update this ticket as I delve into this.

@gunters63
Copy link
Author

Here is the repo: https://github.com/gunters63/issue-2070, just use npx tsc --noemit to reproduce
I think I will give it a try to fix the issue with a PR over the weekend

@gunters63
Copy link
Author

I don't really fully understand the implications of default exports/imports with Typescript 4.8.3 and NodeNext resolution yet (other than default exports seem to be frowned upon now :)). But an easy solution would probably be just to add this line:

export { KeyboardReact };

to index.ts and in index.modern.ts.

This enables me to import the module like this:

import { KeyboardReact } from "react-simple-keyboard";

I couldn't get it to work with default exports/imports.

@gunters63
Copy link
Author

The following workaround works for me (see end of first comment microsoft/TypeScript#50690 (comment)):

import { default as KeyboardBad } from 'react-simple-keyboard';
// Work around typings issue, see: https://github.com/microsoft/TypeScript/issues/50690#issuecomment-1241464619
const Keyboard = KeyboardBad as unknown as typeof KeyboardBad.default;

@hodgef hodgef closed this as completed in c931dd1 Sep 30, 2022
@hodgef hodgef added 💥 Bug Something isn't working and removed 🔍 Investigating Investigating what's causing the issue labels Sep 30, 2022
@hodgef
Copy link
Owner

hodgef commented Sep 30, 2022

Hey @gunters63, sorry for the delay.

I have pushed your proposed fix and it seems to work great:
https://github.com/hodgef/react-simple-keyboard/blob/master/build/index.d.ts#L4

Feel free to give it a try on the latest version.

Thanks!
Francisco Hodge

hodgef added a commit to hodgef/simple-keyboard that referenced this issue Sep 30, 2022
hodgef added a commit to simple-keyboard/simple-keyboard-layouts that referenced this issue Sep 30, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
💥 Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants