-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[bug] TemplateStringsArray is incompatible with literal array type #16552
Comments
I think this is contingent on #16592. |
Actually, I don't know if this will work even with the changes I have in mind. interface MyCustomType extends TemplateStringsArray {
0: "SELECT id FROM users"
} |
That would be fine. I'm going to be auto-generating these definitions anyway, by parsing the code to see which functions are called. This would be very much a workaround for #16551. At the moment, that doesn't seem to work either though. |
declare function id<T extends string>(list: Array<T>): Array<T>;
declare function readonlyId<T extends string>(list: ReadonlyArray<T>): ReadonlyArray<T>;
type LiteralType = "foo" | "bar";
const array: Array<LiteralType> = [];
const readonlyArray: ReadonlyArray<LiteralType> = [];
const foo: ReadonlyArray<LiteralType> = id(array);
const bar: ReadonlyArray<LiteralType> = readonlyId(array);
// ~~~
// Type 'ReadonlyArray<string>' is not assignable to type 'ReadonlyArray<LiteralType>'.
// Type 'string' is not assignable to type 'LiteralType'.const bar: ReadonlyArray<LiteralType>
const baz: ReadonlyArray<LiteralType> = readonlyId(readonlyArray); Isn't it a bug that generic type information is being lost when |
@R00GER that looks like a separate bug, it should probably have its own issue. |
@DanielRosenwasser can you give an update on next steps here? |
There shouldn't be a type interface SQL<TSA, VS> {
texts: TSA;
values: VS;
}
function sql<TSA extends readonly string[], VS extends any[]>(texts:TSA, ...values: VS): SQL<TSA, VS> {
return { texts, values };
}
// then
let s: SQL<['select * from person where a=', ' and b=', ''], [number, Date]> = sql`select * from person where a=${1} and b=${new Date()}`; |
TypeScript Version: 2.4.0
Code
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 thesql
function for each query.Actual behavior:
I get the error:
The text was updated successfully, but these errors were encountered: