Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Typescript support #5

Open
threeaccents opened this issue Jul 4, 2019 · 14 comments
Open

Typescript support #5

threeaccents opened this issue Jul 4, 2019 · 14 comments
Labels
Type: Enhancement New feature or request

Comments

@threeaccents
Copy link

threeaccents commented Jul 4, 2019

Version

^1.0.0

Test Environment

Brave, mac OSX 10.14.1

Current Behavior

No types file present in repo. Or in @types repo. Cannot use library in TypeScript project.

import ImageEditor from '@toast-ui/react-image-editor' // Could not find a declaration file for module '@toast-ui/react-image-editor'

import ImageEditor = require('tui-image-editor'); // import =` is not supported by @babel/plugin-transform-typescript Please consider using `import <moduleName> from '<moduleName>';` alongside Typescript's --allowSyntheticDefaultImports option.

Expected Behavior

Be able to use library in TypeScript project.

@threeaccents
Copy link
Author

For anyone looking for a workaround:

  1. Create a react-image-editor.d.ts file with the following content
declare module '@toast-ui/react-image-editor';
  1. Import it to the component using ImageEditor
/// <reference path="./react-image-editor.d.ts" />
import ImageEditor from '@toast-ui/react-image-editor';

@junghwan-park junghwan-park added the Type: Enhancement New feature or request label Jul 12, 2019
@junghwan-park
Copy link
Member

@threeaccents I'll add type definition file. Thank you for your report.

@indfnzo
Copy link

indfnzo commented Jul 30, 2019

@threeaccents I'll add type definition file. Thank you for your report.

Thanks, this would be great :)

Currently, we've had to ts-ignore the imports to make it work:

// @ts-ignore
import ImageEditor from '@toast-ui/react-image-editor';
import 'tui-image-editor/dist/tui-image-editor.css';

If we have a mapped set of options for the props like includeUI, that would be even better.

@junqdu
Copy link

junqdu commented Mar 12, 2020

@junghwan-park Just wondering, is this issue resolved?

@Distortedlogic
Copy link

Typescript available yet?

@swtalk
Copy link

swtalk commented Nov 13, 2020 via email

@nghieptiki
Copy link

nghieptiki commented Nov 16, 2020

It's works perfect for me.

image

Create a react-image-editor.d.ts

declare module '@toast-ui/react-image-editor' {
  import ImageEditor from 'tui-image-editor';

  type Props = ConstructorParameters<typeof ImageEditor>[1];

  export default function BaseImageEditor(props: Props): JSX.Element;
}

@swtalk
Copy link

swtalk commented Nov 16, 2020 via email

@Distortedlogic
Copy link

@nghieptiki thanks! Ill give it another try with your TS declaration

@swtalk
Copy link

swtalk commented Nov 16, 2020 via email

@AKclown
Copy link

AKclown commented Jun 15, 2021

Does typescript support? I introduced the module and reported an error:

import 'tui-image-editor/dist/tui-image-editor.css';
import ImageEditor from '@toast-ui/react-image-editor';

Cannot find module '@toast-ui/react-image-editor' or its corresponding type declarations.ts(2307)

I used the above answer to no avail
53dd2d8ab62884d9126901f74d36e2fa1e5c13147d1c54eaa1381c370a6499d9QzpcVXNlcnNcYWtcQXBwRGF0YVxSb2FtaW5nXERpbmdUYWxrXDg5NDM0NzM1X3YyXEltYWdlRmlsZXNcMTYyMzc0MDE1Njk2MF9FOURCNERGQS1GODg4LTQzNTctQjhCMS04NEFENUE2RTRDREYucG5n

@swtalk
Copy link

swtalk commented Jun 15, 2021 via email

@AKclown
Copy link

AKclown commented Jun 15, 2021

Does typescript support? I introduced the module and reported an error:

import 'tui-image-editor/dist/tui-image-editor.css';
import ImageEditor from '@toast-ui/react-image-editor';

Cannot find module '@toast-ui/react-image-editor' or its corresponding type declarations.ts(2307)

I used the above answer to no avail
53dd2d8ab62884d9126901f74d36e2fa1e5c13147d1c54eaa1381c370a6499d9QzpcVXNlcnNcYWtcQXBwRGF0YVxSb2FtaW5nXERpbmdUYWxrXDg5NDM0NzM1X3YyXEltYWdlRmlsZXNcMTYyMzc0MDE1Njk2MF9FOURCNERGQS1GODg4LTQzNTctQjhCMS04NEFENUE2RTRDREYucG5n

The reason for the error is the package version problem,
@toast-ui/react-image-editor: 3.14.3 version problem, when I changed to 3.14.2, it ran well

@swtalk
Copy link

swtalk commented Jun 15, 2021 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants