question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot export `declare`d functions in flow

See original GitHub issue

Bug Report

  • I would like to work on a fix!

Current behavior A clear and concise description of the behavior.

Input Code

declare function foo(): void;
export { foo };

Expected behavior

This should parse without an error.

Babel Configuration

repros just using preset flow

Environment

  • Babel version(s): v7.11.1

Possible Solution

This should work fine as it’s no different to either of these working cases

declare export function bar(): void;

declare var bam: string;
export { bam };

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolo-ribaudocommented, Feb 1, 2021

I’m trying to fix this, and Flow’s scope handling of declare functions seems completely random:

// error
function A(): void {}
declare function A(): void;
// ok
declare function A(): void;
function A(): void {}
// ok
declare function A(): void;
function A(): void {}
declare function A(): void;
1reaction
bradzachercommented, Feb 1, 2021

I get your reasoning - but:

  • If you’re banning declare function foo(): void; export { foo };, then you should also ban the variable decl case: declare var bam: string; export { bam };.
    • Otherwise there is a distinct asymmetry in babel’s logic.
  • Why is declare export function foo(): void allowed? By your reasoning it should be banned.
  • Most importantly: flow declaration files ofc do these practices, which is where it’s used, and why it shouldn’t be banned.

I don’t think babel should be in the business of validating semantics this deeply

Read more comments on GitHub >

github_iconTop Results From Across the Web

Declare default export among other exports #1806 - GitHub
I'm experimenting with using module.name_mapper to replace the file from which Flow gets type info for this module, and this seems to work....
Read more >
javascript - why I can't export export a declared function in ES6?
It just doesn't flow well without braces. Share.
Read more >
Solved: Flow goes lost while export/importing a solution b...
I m trying to export this solution and import it into Environment B. ... The flow wont be connected when i try and...
Read more >
Creating Library Definitions | Flow
To declare a global function that should be accessible throughout your project, use the declare function syntax in a libdef file: flow-typed/myLibDef.js ...
Read more >
export - JavaScript - MDN Web Docs
The export declaration is used to export values from a JavaScript module. ... also var, let export function functionName() { /* …
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found