I'm running into a situation where my code snippet works perfectly in TS
, but encounters errors in flow
. Is there a workaround to make it function correctly in flow
as well?
type field = 'me' | 'you'
type fieldWithKeyword = `${field}.keyword` // encountering errors in flow
const appendKeyword = (val:field): fieldWithKeyword => {
return `${val}.keyword`
}
appendKeyword('me') // functions fine in TS
The goal is to define two types, field
and fieldWithKeyword
. The fieldWithKeyword
type should be able to accept values that follow the format ${field}.keyword
(for example, 'me.keyword'
and 'you.keyword'
are valid values for fieldWithKeyword
)