microsoft / microsoft/TypeScript
[bug] TemplateStringsArray is incompatible with literal array type
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript 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'.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the self-contained demonstration in src/index.ts and trace how TypeScript 2.4 checks the sqlSELECT id FROM users call against the declared literal-array parameter. Done means the example type-checks and querySync receives the expected Array<{id: number}> result without the TemplateStringsArray error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100