facebook / facebook/flow

.flowconfig option module.name_mapper can't map to a lib definition

未關閉
#1,322 12 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
Rust
星號
22.3k
分支
1.9k
PR 合併指標
30 天內沒有已合併 PR

描述

Repro:

.flowconfig

```
[lib]
lib
[options]
module.name_mapper='1Doesnt\(Exist\)' -> '\1s'
```

A.js

``` javascript
/* @flow */
var m1 = require('./1DoesntExist'); // actual error: can't find module 1DoesntExist
var a_1: string = m1.numVal; // expected error: number ~> string
```

lib/Exists.js

``` javascript
declare module 'Exists' {
declare var exports: {
numVal: number;
};
};
```

Expected output:

```
A.js:3:19,27: number
This type is incompatible with
A.js:3:10,15: string
```

Actual output:

```
A.js:2:22,37: ./1DoesntExist
Required module not found
```

Workaround:
While libdefs aren't working, it's still possible to map to a node module. There's an npm module called `empty` that can be useful here. See [this gist](https://gist.github.com/lambdahands/d19e0da96285b749f0ef) for a complete example.

I think the issue is that we do name mapping specifically against file paths, so the code just doesn't attempt to handle this case. I think that it should. cc @jeffmo, who originally added this feature.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。