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

Remove namespace from Typescript definition #64

Merged
merged 3 commits into from
Jun 25, 2018

Conversation

smvilar
Copy link
Contributor

@smvilar smvilar commented Jun 20, 2018

I'm not sure if it's a bug or it's just that I don't understand how the namespace works, but currently in order to do

import { CustomPIXIComponent } from 'react-pixi-fiber';

instead Typescript requires me to write

import { CustomPIXIComponentNamespace } from 'react-pixi-fiber';
CustomPIXIComponentNamespace.CustomPIXIComponent

and then the compiled JS code fails because
Uncaught TypeError: Cannot read property 'CustomPIXIComponent' of undefined

I think this namespace should be removed.

@codecov
Copy link

codecov bot commented Jun 20, 2018

Codecov Report

Merging #64 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #64   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines         204    204           
=====================================
  Hits          204    204

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e1b628...ae28709. Read the comment docs.

@michalochman
Copy link
Owner

@Fabiantjoeaon care to elaborate?

@Fabiantjoeaon
Copy link
Contributor

Hmm I see. I added this namespace around CustomPIXIComponent because of this issue (that has already been closed):
#54

I think removing it might cause to re-create this bug. Perhaps there is another solution ? @smvilar

@smvilar
Copy link
Contributor Author

smvilar commented Jun 24, 2018

Hi @Fabiantjoeaon, I don't understand how to reproduce the bug you were having. Is it building the lib itself?
I'm not sure why you added that namespace, since from what I understand, if I were using this lib in JS I'd write:

import { CustomPIXIComponent } from 'react-pixi-fiber';

so that's probably what I want to do also in TS. If I'm forced to write

import { CustomPIXIComponentNamespace } from 'react-pixi-fiber';

that just resolves to undefined, since it doesn't exist.

I honestly thought that nobody was using this lib from TS since it just doesn't compile. You can see it even in test/typescript/index.tsx:

image

@smvilar smvilar force-pushed the patch-1 branch 3 times, most recently from 0f5afa2 to 8b96536 Compare June 24, 2018 22:24
@smvilar
Copy link
Contributor Author

smvilar commented Jun 24, 2018

I just updated the branch to include a functional TS test that you can run, just type

yarn --pure-lockfile // to install typescript
yarn test:ts

and it will compile the test.
You can try with or without the 2nd commit in the branch (the actual fix) to see the difference.

@Fabiantjoeaon
Copy link
Contributor

Hi @smvilar

I tried running your tests. All good.

Regarding reproducing my bug, whenever I remove the namespace from the package in my node_modules directly, I still get the following error:

schermafbeelding 2018-06-25 om 10 07 51

To be fair, I agree with you that this namespace should be removed, because my solution to solve this error was not very clean, and I think it should be solved in a different way. Perhaps it has something to do with my Typescript version?

What version are you running, and is this installed globally? (because I don't have TS installed globally)

I get the error whenever I use my workspace's version (2.8.3), and when I use my VSCode's version (2.9.1),

@Fabiantjoeaon
Copy link
Contributor

Fabiantjoeaon commented Jun 25, 2018

Okay I figured it out!

  • I found out we apparently added a own typings file which already included a export for CustomPIXIComponent, which explains my duplicate decleration, apparently to fix another bug that has already been fixed.
  • Got it working with TS version 2.9.2

I guess you can merge this fix.

@michalochman
Copy link
Owner

michalochman commented Jun 25, 2018

@Fabiantjoeaon thanks for clarification!

@smvilar I'm going to merge your fix, thanks for bringing that problem up :) can you just update @types/react to the same version that's used in peerDependencies?

@smvilar
Copy link
Contributor Author

smvilar commented Jun 25, 2018

@michalochman ready. Please note that I added a script to test Typescript typings, maybe you want to add this to the CI?

@smvilar
Copy link
Contributor Author

smvilar commented Jun 25, 2018

@Fabiantjoeaon so glad we could figure this out!

@michalochman
Copy link
Owner

@smvilar can you just add the following line to .circleci/config.yml file after current test command?

- run: yarn test:ts

Thanks!

@smvilar
Copy link
Contributor Author

smvilar commented Jun 25, 2018

@michalochman done! Let's see how it works

@smvilar
Copy link
Contributor Author

smvilar commented Jun 25, 2018

They passed 😄
image

@michalochman
Copy link
Owner

@smvilar cool! Much appreciated

@michalochman michalochman merged commit 47132b1 into michalochman:master Jun 25, 2018
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.

3 participants