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

Fix server-side type definitions #95

Merged
merged 1 commit into from
Jun 13, 2018
Merged

Fix server-side type definitions #95

merged 1 commit into from
Jun 13, 2018

Conversation

jiripudil
Copy link
Contributor

@jiripudil jiripudil commented May 30, 2018

Hello, I'm trying to use this awesome package with Typescript on the server, and I've had some difficulties.

When I import {getLoadableState} from 'loadable-components/server', The Typescript compiler complains that it "Could not find a declaration file for module 'loadable-components/server'." I've managed to work around this by explicitly setting the path mapping in tsconfig.json to "loadable-components/*": ["node_modules/loadable-components/types"], but I feel that's an unnecessary step for the end user.

This PR thus extracts the server-side type definitions to a separate server.d.ts to match the structure of the JS modules, which seems to be the recommended way.

I've also added a type definition for the DeferredState which wasn't exposed before.

@codecov
Copy link

codecov bot commented May 30, 2018

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff           @@
##           master     #95   +/-   ##
======================================
  Coverage    90.5%   90.5%           
======================================
  Files          15      15           
  Lines         200     200           
  Branches       54      54           
======================================
  Hits          181     181           
  Misses         17      17           
  Partials        2       2

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 0a119f8...c2af81a. Read the comment docs.

"strictFunctionTypes": false,
"baseUrl": ".",
"paths": {
"loadable-components": ["."],
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is how it could be fixed!?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean? The module resolution works out of the box as soon as this package is in node_modules, but within the repository, the compiler seems to need a little hint to be able to locate the module. I don't know if it's the best way, but it works :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wrote the initial TS definitions, and fail to get dtslint working with server as a separate file.
You just fixed it, it the quite straight way, the way I could not figure out of dtslint documentation.
According to them - everything should work even without patching tsconfig, and I will not be surprised if it will, but they wont 💩 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Submodules are apparently more complicated :) I'm not too fond of the fact that while most type definitions are in types/, the server.d.ts suddenly has to be in the package root. But it seems to be the way to go 🤷‍♂️

@gregberge
Copy link
Owner

Thanks!

@gregberge gregberge merged commit 8402c19 into gregberge:master Jun 13, 2018
@jiripudil jiripudil deleted the patch-1 branch June 13, 2018 13:44
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