diff --git a/internal/checker/relater.go b/internal/checker/relater.go index c682637f41..0551862f18 100644 --- a/internal/checker/relater.go +++ b/internal/checker/relater.go @@ -3298,6 +3298,22 @@ func (r *Relater) structuredTypeRelatedToWorker(source *Type, target *Type, repo return result } } + case source.flags&TypeFlagsTemplateLiteral != 0: + if slices.Equal(source.AsTemplateLiteralType().texts, target.AsTemplateLiteralType().texts) { + result = TernaryTrue + for i, sourceType := range source.AsTemplateLiteralType().types { + targetType := target.AsTemplateLiteralType().types[i] + result &= r.isRelatedTo(sourceType, targetType, RecursionFlagsBoth, false /*reportErrors*/) + if result == TernaryFalse { + return result + } + } + return result + } + case source.flags&TypeFlagsStringMapping != 0: + if source.AsStringMappingType().Symbol() == target.AsStringMappingType().Symbol() { + return r.isRelatedTo(source.AsStringMappingType().target, target.AsStringMappingType().target, RecursionFlagsBoth, false /*reportErrors*/) + } } if source.flags&TypeFlagsObject == 0 { return TernaryFalse diff --git a/testdata/baselines/reference/submodule/compiler/assignmentToConditionalBrandedStringTemplateOrMapping.errors.txt b/testdata/baselines/reference/submodule/compiler/assignmentToConditionalBrandedStringTemplateOrMapping.errors.txt deleted file mode 100644 index ba0ef1ca15..0000000000 --- a/testdata/baselines/reference/submodule/compiler/assignmentToConditionalBrandedStringTemplateOrMapping.errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -assignmentToConditionalBrandedStringTemplateOrMapping.ts(4,1): error TS2719: Type '() => T extends `${"a" & { a: 1; }}` ? 1 : 2' is not assignable to type '() => T extends `${"a" & { a: 1; }}` ? 1 : 2'. Two different types with this name exist, but they are unrelated. - Type 'T extends `${"a" & { a: 1; }}` ? 1 : 2' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. Two different types with this name exist, but they are unrelated. - Type '1 | 2' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. - Type '1' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. -assignmentToConditionalBrandedStringTemplateOrMapping.ts(9,1): error TS2719: Type '() => T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2' is not assignable to type '() => T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. Two different types with this name exist, but they are unrelated. - Type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. Two different types with this name exist, but they are unrelated. - Type '1 | 2' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. - Type '1' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. - - -==== assignmentToConditionalBrandedStringTemplateOrMapping.ts (2 errors) ==== - let a: (() => T extends `${'a' & { a: 1 }}` ? 1 : 2) = null!; - let b: (() => T extends `${'a' & { a: 1 }}` ? 1 : 2) = null!; - - a = b; - ~ -!!! error TS2719: Type '() => T extends `${"a" & { a: 1; }}` ? 1 : 2' is not assignable to type '() => T extends `${"a" & { a: 1; }}` ? 1 : 2'. Two different types with this name exist, but they are unrelated. -!!! error TS2719: Type 'T extends `${"a" & { a: 1; }}` ? 1 : 2' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. Two different types with this name exist, but they are unrelated. -!!! error TS2719: Type '1 | 2' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. -!!! error TS2719: Type '1' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. - - let c: (() => T extends Uppercase<'a' & { a: 1 }> ? 1 : 2) = null!; - let d: (() => T extends Uppercase<'a' & { a: 1 }> ? 1 : 2) = null!; - - c = d; - ~ -!!! error TS2719: Type '() => T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2' is not assignable to type '() => T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. Two different types with this name exist, but they are unrelated. -!!! error TS2719: Type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. Two different types with this name exist, but they are unrelated. -!!! error TS2719: Type '1 | 2' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. -!!! error TS2719: Type '1' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/assignmentToConditionalBrandedStringTemplateOrMapping.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/assignmentToConditionalBrandedStringTemplateOrMapping.errors.txt.diff deleted file mode 100644 index ff7b747ff9..0000000000 --- a/testdata/baselines/reference/submodule/compiler/assignmentToConditionalBrandedStringTemplateOrMapping.errors.txt.diff +++ /dev/null @@ -1,35 +0,0 @@ ---- old.assignmentToConditionalBrandedStringTemplateOrMapping.errors.txt -+++ new.assignmentToConditionalBrandedStringTemplateOrMapping.errors.txt -@@= skipped -0, +0 lines =@@ -- -+assignmentToConditionalBrandedStringTemplateOrMapping.ts(4,1): error TS2719: Type '() => T extends `${"a" & { a: 1; }}` ? 1 : 2' is not assignable to type '() => T extends `${"a" & { a: 1; }}` ? 1 : 2'. Two different types with this name exist, but they are unrelated. -+ Type 'T extends `${"a" & { a: 1; }}` ? 1 : 2' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. Two different types with this name exist, but they are unrelated. -+ Type '1 | 2' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. -+ Type '1' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. -+assignmentToConditionalBrandedStringTemplateOrMapping.ts(9,1): error TS2719: Type '() => T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2' is not assignable to type '() => T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. Two different types with this name exist, but they are unrelated. -+ Type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. Two different types with this name exist, but they are unrelated. -+ Type '1 | 2' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. -+ Type '1' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. -+ -+ -+==== assignmentToConditionalBrandedStringTemplateOrMapping.ts (2 errors) ==== -+ let a: (() => T extends `${'a' & { a: 1 }}` ? 1 : 2) = null!; -+ let b: (() => T extends `${'a' & { a: 1 }}` ? 1 : 2) = null!; -+ -+ a = b; -+ ~ -+!!! error TS2719: Type '() => T extends `${"a" & { a: 1; }}` ? 1 : 2' is not assignable to type '() => T extends `${"a" & { a: 1; }}` ? 1 : 2'. Two different types with this name exist, but they are unrelated. -+!!! error TS2719: Type 'T extends `${"a" & { a: 1; }}` ? 1 : 2' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. Two different types with this name exist, but they are unrelated. -+!!! error TS2719: Type '1 | 2' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. -+!!! error TS2719: Type '1' is not assignable to type 'T extends `${"a" & { a: 1; }}` ? 1 : 2'. -+ -+ let c: (() => T extends Uppercase<'a' & { a: 1 }> ? 1 : 2) = null!; -+ let d: (() => T extends Uppercase<'a' & { a: 1 }> ? 1 : 2) = null!; -+ -+ c = d; -+ ~ -+!!! error TS2719: Type '() => T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2' is not assignable to type '() => T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. Two different types with this name exist, but they are unrelated. -+!!! error TS2719: Type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. Two different types with this name exist, but they are unrelated. -+!!! error TS2719: Type '1 | 2' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. -+!!! error TS2719: Type '1' is not assignable to type 'T extends Uppercase<`${"a" & { a: 1; }}`> ? 1 : 2'. -+ \ No newline at end of file