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

Proposal: TS no-var-requires set to false #24

Open
nazrhom opened this issue May 14, 2018 · 1 comment
Open

Proposal: TS no-var-requires set to false #24

nazrhom opened this issue May 14, 2018 · 1 comment

Comments

@nazrhom
Copy link

nazrhom commented May 14, 2018

I am currently having troubles with this rule when dealing with conditional imports. I couldn't find a nice way to do this that does not violate the rule (e.g. http://ideasintosoftware.com/typescript-conditional-imports/) as it is not possible to use import statements that are not on the top-level.
Do we have a good workaround for this case? Dynamic imports could be a solution but they are a bit clunky in some cases as they are async and must be handled with promises

@nazrhom nazrhom closed this as completed May 14, 2018
@nazrhom nazrhom reopened this May 14, 2018
@nazrhom nazrhom assigned LucianBuzzo, hedss and Page- and unassigned Page-, hedss and LucianBuzzo May 15, 2018
@pimterry
Copy link

You can use dynamic imports instead. They look like:

import('path').then((path) => ...)

This means you have to deal with a promise, but all the typing etc still works correctly, which is the big problem with the var/const alternative. We do this in the cli, with async/await too, to lazily do expensive requires, like so: https://github.com/resin-io/resin-cli/blob/master/lib/actions/push.ts#L109-L112

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

No branches or pull requests

5 participants