[bug] TemplateStringsArray is incompatible with literal array type
See original GitHub issueTypeScript Version: 2.4.0
Code
// A *self-contained* demonstration of the problem follows...
interface SQLQuery<TResult> {
__result: TResult;
}
declare function sql(
literals: ['SELECT id FROM users'],
...placeholders: any[]
): SQLQuery<{id: number}>;
declare function querySync<TResult>(q: SQLQuery<TResult>): Array<TResult>;
const values: Array<{id: number}> = querySync(sql`SELECT id FROM users`);
Expected behavior:
Typescript should see that the input string ‘SELECT id FROM users’ matches the expected literals of ['SELECT id FROM users']
and use the declared function, allowing me to generate an overloaded version of the sql
function for each query.
Actual behavior:
I get the error:
src/index.ts(23,50): error TS2345: Argument of type ‘TemplateStringsArray’ is not assignable to parameter of type ‘[“SELECT id FROM users”]’. Property ‘0’ is missing in type ‘TemplateStringsArray’.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (5 by maintainers)
Top Results From Across the Web
flowtype cannot return object literal because object type is ...
When I run flow over this function, I get the following error: Cannot return object literal because object type [1] is incompatible with ......
Read more >Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >Documentation - Template Literal Types - TypeScript
Generating mapping types which change properties via template literal strings.
Read more >Overview - TypeScript
can be rewritten as the following array literal ... union member and have the appropriate type, meaning that the sample above correctly issues...
Read more >Arrays - Flow
Array types are simply instantiations of a special polymorphic Array ... Flow would report an error for an incompatible element write a[i] =...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@DanielRosenwasser can you give an update on next steps here?
Isn’t it a bug that generic type information is being lost when
ReadonlyArray
is assigned toArray
?