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

How to reuse types in declaration files. Bug? #1778

Closed
zerkalica opened this issue May 12, 2016 · 1 comment
Closed

How to reuse types in declaration files. Bug? #1778

zerkalica opened this issue May 12, 2016 · 1 comment

Comments

@zerkalica
Copy link

zerkalica commented May 12, 2016

I try to reuse exported interfaces between declaration files, but got an error:

src/index.js:4
  4:     TestFn
         ^^^^^^ Named import from module `flowtest`. This module has no named export called `TestFn`.
// flow-typed/flow-test-a.js
/* @flow */

declare module 'flowtest' {
    declare type TestFn = Function;
}
// flow-typed/flow-test-b.js
/* @flow */

import type {
    TestFn
} from 'flowtest'
// src/index.js
/* @flow */

import type {
    TestFn
} from 'flowtest'

Problem with filenames sorting, if i rename flow-test-a.js to flow-test-c.js, all works fine. Probably bug?
I created repository with this files: https://github.com/zerkalica/flowtest-bug

How to reuse types in project itself alike in imported projects?

In flow examples i found only ugly hack: all reusable types are prefixed and placed in one big file with exported declarations, like buffer$NonBufferEncoding.

But i want to write types once for internal and external purposes and place them in multiple files.

@samwgoldman
Copy link
Member

This is something we're working on (see flow-typed/flow-typed#16), but for now the recommended way is to create a top-level declaration with a prefix containing the module name and $. For example, for a module foo, something like this:

class foo$Foo {
  // ...
}

declare module foo {
  declare var Foo = typeof foo$Foo;
}

Then you can depend on the top-level declaration from another module declaration, bar:

declare module bar {
  declare class Bar extends foo$Foo {
    // ...
  }
}

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

2 participants