-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Type containing templated, branded string is not assignable to itself #61098
Comments
Note: bisecting the issue reveals that the regression was introduced in #52836. |
Update: appears this issue is also present for the string mapping types like export let a: <T>() => T extends Uppercase<'a' & { a: 1 }> ? 1 : 2 = null!;
export let b: <T>() => T extends Uppercase<'a' & { a: 1 }> ? 1 : 2 = null!;
a = b; // β Error! |
I believe this issue can be fixed by inserting the following code at line 23006 of checker.ts, in the function if (sourceFlags & TypeFlags.TemplateLiteral) {
if (arrayIsEqualTo((source as TemplateLiteralType).texts, (target as TemplateLiteralType).texts)) {
const sourceTypes = (source as TemplateLiteralType).types;
const targetTypes = (target as TemplateLiteralType).types;
result = Ternary.True;
for (let i = 0; i < sourceTypes.length; i++) {
if (!(result &= isRelatedTo(sourceTypes[i], targetTypes[i], RecursionFlags.Both, false))) {
break;
}
}
return result;
}
}
if (sourceFlags & TypeFlags.StringMapping) {
if ((source as StringMappingType).symbol === (target as StringMappingType).symbol) {
return isRelatedTo((source as IndexType).type, (target as IndexType).type, RecursionFlags.Both, false);
}
} Let me know if you want me to open a PR. |
We can look at a PR, but we won't merge it if it re-regresses #52345 |
@RyanCavanaugh cool, PR submitted! Not sure how to test if the fix re-regesses #52345 however. |
π Search Terms
brand branded tag tagged template string not assignable extends different type name unrelated
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?#code/FAUwHgDg9gTgLgAgDYkQQwFwIBQB4AqAfNgJQIC8hC+C4cIAdgCYDOCABgCQDeA5GrwQAyBNwSYEARgQBfGewQB+KQiwAmMuQQMArkiQBCANyhIsRCkQAjLHiKkKVGnUasOPfoJFiJ0uQuVpdU1tPUMTYDQKBCsjIA
π» Code
π Actual behavior
Typescript error:
π Expected behavior
No error
Additional information about the issue
I would expect that, as a general principle, any type which is copy-and-pasted from one place to another should be assignable to itself. (With the exception of
unique symbol
, since by design it's supposed to not do what I just said.) This is perhaps the most lax notion of assignability that could possibly exist, I would think.Note that, as soon as I remove either the outer template or the inner brand, assignability works as expected once again.
The text was updated successfully, but these errors were encountered: