Skip to content

Instantly share code, notes, and snippets.

@Bannerets
Created July 7, 2019 12:56
Show Gist options
  • Save Bannerets/57fda44a56167bdeca87dcc94af787c4 to your computer and use it in GitHub Desktop.
Save Bannerets/57fda44a56167bdeca87dcc94af787c4 to your computer and use it in GitHub Desktop.
$Flow$ModuleRef
[ignore]
[include]
[libs]
[lints]
[options]
module.system=haste
module.system.haste.module_ref_prefix=m#
[strict]
// @flow
declare export var str1: 'str1'
export function sayHi(name: string) {
console.log('hi, ' + name)
}
// @flow
declare export var str2: 'str2'
// @flow
export function sayHi(name: string) {
console.log('hello, ' + name)
}
// @flow
declare function requireMany<T>(T)
: $TupleMap<T, <M>($Flow$ModuleRef<M>) => M>
const t = requireMany(['m#./a', 'm#./b'])
const a = t[0] // {| +sayHi: (name: string) => void, +str1: "str1" |}
const b = t[1] // {| +str2: "str2" |}
// ---
interface HiModule {
+sayHi: string => void
}
declare function requireHi<M: HiModule>($Flow$ModuleRef<M>): M
// or:
// declare function requireHi<M: { sayHi: string => void, ... }>($Flow$ModuleRef<M>): M
const h1 = requireHi('m#./a') // ok
const h2 = requireHi('m#./b') // error
const h3 = requireHi('m#./c') // ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment