Open evgenylink opened 3 years ago
Tested on
Playground link
Following Generic Constraints
type Concatable<T> = { concat: (...xss: T[]) => T }; export const concat = <T extends Concatable<T>> (xs: T, ...xss: T[] ): T => xs.concat( ...xss ); export const test_1 = concat([1, 2], [3, 4]); // OK export const test_2 = concat("foo" as string, "bar"); // OK export const test_3 = concat<string>("foo", "bar"); // OK // Expected: 'test_4: string' // Got: 'test_4: Concatable<"foo" | "bar">' export const test_4 = concat("foo", "bar"); // Error: ^^^^^ // Argument of type 'string' is not assignable to // parameter of type 'Concatable<"foo" | "bar">'
test_4: Concatable<"foo" | "bar">
TS leaks the constraint for type T into type T TS provides no good way to make Rust-like trait
T, test_4, "foo" and "bar" all infer type string
string
@DanielRosenwasser any idea why the Concatable constraint creates a literal context? Seems wrong
Concatable
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
Tested on
⏯ Playground Link
Playground link
💻 Code
Following Generic Constraints
🙁 Actual behavior
test_4: Concatable<"foo" | "bar">
TS leaks the constraint for type T into type T TS provides no good way to make Rust-like trait
🙂 Expected behavior
T, test_4, "foo" and "bar" all infer type
string