-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encaps error when tag template returns object #579
Comments
Is it valid to return anything other than a string from a tagged template? |
If so, this should be pretty simple to fix. Tagged template expressions currently assume the tag function returns a string and the expression itself is a string. Reference Type_inference_js.ml. |
Yeah it's just a CallExpression, the only special part is the arguments it receives. The most permissive type for a function used as a template tag: f(strings: (Array<string>) & ({raw: Array<string>}), ...args: any) Edit: flow seems to not like that type definition Also strings and strings.raw are frozen, and |
Thanks for the details! Unfortunately, array&object intersections don't currently do what you expect, but I think that's incompleteness, not intentional. Flow also doesn't know what a frozen array is, for a similar issue (arrays are pretty different from objects in flow, but are objects in JS). For now, though, the associated PR lets you return non-string values. I'll make sure we track those other two constraints in #560. |
This is the minimal:
Gives:
In the actual situation it's returning a well typed object.
The only way to avoid the error I've found is to declare the function's return type and the variable's type explicitly to
any
.The text was updated successfully, but these errors were encountered: