Skip to content
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

Compiling v2.7.0 from npm causes a type error #1970

Closed
KonstantinEpam23 opened this issue Dec 21, 2022 · 2 comments · Fixed by #2126
Closed

Compiling v2.7.0 from npm causes a type error #1970

KonstantinEpam23 opened this issue Dec 21, 2022 · 2 comments · Fixed by #2126
Assignees

Comments

@KonstantinEpam23
Copy link
Collaborator

Steps to Reproduce

  1. Compile the app from npm v2.7.0-rc.4 (you may have to replace the package versions in example/package.json to point to the exact version)
    Example:
  "dependencies": {
    "ketcher-core": "2.7.0-rc.4",
    "ketcher-react": "2.7.0-rc.4",
    "ketcher-standalone": "2.7.0-rc.4",
...
  1. Run yarn build

Actual behavior
A compilation error occurs:

#10 95.45 Failed to compile.                                                                                                                                                                               
#10 95.45 
#10 95.45 TS2322: Type '(ketcher: Ketcher) => Promise<void>' is not assignable to type '(ketcher: Ketcher) => void'.
#10 95.45   Types of parameters 'ketcher' and 'ketcher' are incompatible.
#10 95.45     Type 'import("/src/node_modules/ketcher-react/node_modules/ketcher-core/dist/application/ketcher").Ketcher' is not assignable to 
              type 'import("/src/node_modules/ketcher-core/dist/application/ketcher").Ketcher'.
#10 95.45       Property '#private' in type 'Ketcher' refers to a different member that cannot be accessed from within type 'Ketcher'.
#10 95.45     49 |         structServiceProvider={structServiceProvider}
#10 95.45     50 |         buttons={this.getHiddenButtonsConfig(this.state.hiddenButtons ?? [])}
#10 95.45   > 51 |         onInit={this.handleOnInit}
#10 95.45        |         ^^^^^^
#10 95.45     52 |         errorHandler={this.handleError}
#10 95.45     53 |       />
#10 95.45     54 |     );
#10 95.45 
#10 95.45 
#10 95.70 error Command failed with exit code 1.
#10 95.70 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected behavior
No error should be present in console during compilation

Screenshots
image

Ketcher version [e.g. v2.4.2].
v2.7.0

@KonstantinEpam23
Copy link
Collaborator Author

KonstantinEpam23 commented Dec 23, 2022

Looks like the problem may be related to a bug in TypeScript that is reported here: microsoft/TypeScript#49466

Brief explanation of the problem:
This is likely because you have two, distinct copies of Ketcher class, relying on two distinct copies of the nominal Ketcher class (because of its private members) - one in ./packages/ketcher-core/dist (the one reachable via the types in the root import), and one in ./example/dist (the one reachable via the deep import). And we are essentially shipping two distinct packages worth of types.

@Nitvex Nitvex assigned KonstantinEpam23 and unassigned Nitvex Dec 26, 2022
@Nitvex Nitvex added rc.8 and removed rc.7 labels Dec 26, 2022
@KonstantinEpam23
Copy link
Collaborator Author

KonstantinEpam23 commented Dec 27, 2022

Possible workarounds:

  1. Add a // @ts-ignore comment above the line with the error, the project should build successfully
  2. In App.tsx Editor component onInit event - change the type of Ketcher to Promise<Ketcher>
  3. Use the following steps:
  • remove yarn.lock from your project directory and any subdirectories that have package.json
  • remove all "node_modules" directories from the project
  • run yarn cache clean --all
  • run yarn install then yarn build
  • if you are working with the file structure, that is the same as in this repository - run yarn install and yarn build as well from the following directories: "example", "packages/ketcher-react", "packages/ketcher-core", "packages/ketcher-standalone"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants