facebook / facebook/flow

Imported key in computed property results in lack of error detection

Open
#3,454 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

As you can see in the REPL example, Flow detects the lack of definition in the `state` accessed property only when the computed key is a locally defined variable. Isn't this a bug?

```js
/* @flow */
import { IMPORTED_ACTION } from 'imports'
const LOCAL_ACTION = 'ACTION'

type Action = { type: string, payload: Object }
type Handler = {
[key: string]: (state: T, action: $Subtype) => T
}
type MyState = {
items: Array
}

const handler: Handler = {
[IMPORTED_ACTION]: (state, action: Action) => ({
...state,
items: state.items.concat(action.payload.id),
test: state.test
}),
[LOCAL_ACTION]: (state, action: Action) => ({
...state,
items: state.items.concat(action.payload.id),
test: state.test
}),
}
```

```sh
22: test: state.test
^ property `test`. Property not found in
22: test: state.test
^ object type
```

[REPL Example](https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoAlgWwA5wE4AuYA3mAJICyACgPIBKAKgKIAiA+gIIDCDZNAcmAC+YKHjiYwAciy5CAZymoAxnAB28ogBkaXDls48+ggLzTuvAUtQEAntgCmYDsoLp1YM6TuOAXGE08dDUAcwAaMGwAQ1t4KIATfxoAIwArB1dhG3snAAkotXiYBzwAHgYAPk8SVDAwAG0Aawdbf0DgkIBdfwAKTSiCB38GCKjXdzV-ABIAZQBXZJ8HUpc3dQqASk8qhlQhbMcwClsZggGnL1qwdEHMeX8OPDwY0rU5zGSSir3UFXVNMAACwKRRK-nyhWKZWOp3OVUudXqlFojFYhks-G6YD6Z0Go3G6geBLUWxMVR6xCudQAdLT+niqddbvcAriHNSbg47tTVGplAMemM1mpqdFYnAEhz4hswozBpo2mzqfKCFchDKrvUdHoDBZjFiced8cKicLSeTKXUaXS2bKrUyuSz6ezOdzefyCILiaKYnF4lKNfaVYrzsqHJo1Rr9kA)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.