-
Notifications
You must be signed in to change notification settings - Fork 1.9k
string is incompatible with string literal #6789
Copy link
Copy link
Closed
Description
I got flow error from this code snippet
type MyType = 'aa' | 'bb'
const str = 'a'
const test1: MyType = `a${str}` // ERROR
const test2: MyType = 'a' + str // ERROR
Error
const test1: MyType = `a${str}` // ERROR
^ Cannot assign template string to `test1` because: Either string [1] is incompatible with string literal `aa` [2]. Or string [1] is incompatible with string literal `bb` [3].
References:
6: const test1: MyType = `a${str}` // ERROR
^ [1]
3: type MyType = 'aa' | 'bb'
^ [2]
3: type MyType = 'aa' | 'bb' ^ [3]
Does anyone know why flow doesn't support this? Or is there a better way to write this code? Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels