File: stringMappingOverPatternLiterals.errors.txt

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (250 lines) | stat: -rw-r--r-- 13,268 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(25,5): error TS2322: Type '`aA${string}`' is not assignable to type '"aA"'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(26,5): error TS2322: Type '`AA${Uppercase<string>}`' is not assignable to type '"AA"'.
  Type '`AA${string}`' is not assignable to type '"AA"'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(27,5): error TS2322: Type '`aa${Lowercase<string>}`' is not assignable to type '"aa"'.
  Type '`aa${string}`' is not assignable to type '"aa"'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(30,5): error TS2322: Type '`AA${Uppercase<string>}`' is not assignable to type '`aA${string}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(31,5): error TS2322: Type '`aa${Lowercase<string>}`' is not assignable to type '`aA${string}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(33,5): error TS2322: Type '`aA${string}`' is not assignable to type '`AA${Uppercase<string>}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(34,5): error TS2322: Type '`aa${Lowercase<string>}`' is not assignable to type '`AA${Uppercase<string>}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(36,5): error TS2322: Type '`aA${string}`' is not assignable to type '`aa${Lowercase<string>}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(37,5): error TS2322: Type '`AA${Uppercase<string>}`' is not assignable to type '`aa${Lowercase<string>}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(51,5): error TS2322: Type 'string' is not assignable to type 'Uppercase<string>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(52,5): error TS2322: Type 'Lowercase<string>' is not assignable to type 'Uppercase<string>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(53,5): error TS2322: Type 'string' is not assignable to type 'Lowercase<string>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(54,5): error TS2322: Type 'Uppercase<string>' is not assignable to type 'Lowercase<string>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(56,5): error TS2322: Type 'string' is not assignable to type 'Uppercase<string>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(57,5): error TS2322: Type 'string' is not assignable to type 'Lowercase<string>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(78,5): error TS2322: Type 'Uppercase<string>' is not assignable to type 'Uppercase<Lowercase<string>>'.
  Type 'string' is not assignable to type 'Lowercase<string>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(79,5): error TS2322: Type 'Uppercase<string>' is not assignable to type 'Uppercase<Lowercase<string>>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(83,5): error TS2322: Type 'Lowercase<Uppercase<string>>' is not assignable to type 'Uppercase<string>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(84,5): error TS2322: Type 'Lowercase<Uppercase<string>>' is not assignable to type 'Uppercase<string>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(85,5): error TS2322: Type 'Lowercase<Uppercase<string>>' is not assignable to type 'Uppercase<Lowercase<string>>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(87,5): error TS2322: Type 'Uppercase<string>' is not assignable to type 'Lowercase<Uppercase<string>>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(88,5): error TS2322: Type 'Uppercase<string>' is not assignable to type 'Lowercase<Uppercase<string>>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(89,5): error TS2322: Type 'Uppercase<Lowercase<string>>' is not assignable to type 'Lowercase<Uppercase<string>>'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(129,5): error TS2322: Type 'Capitalize<string>' is not assignable to type '`A${string}`'.
  Type 'string' is not assignable to type '`A${string}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(130,5): error TS2322: Type 'Capitalize<string>' is not assignable to type '`A${string}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(131,5): error TS2322: Type 'Capitalize<string>' is not assignable to type '`A${string}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(147,5): error TS2322: Type 'Uncapitalize<string>' is not assignable to type '`a${string}`'.
  Type 'string' is not assignable to type '`a${string}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(148,5): error TS2322: Type 'Uncapitalize<string>' is not assignable to type '`a${string}`'.
tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts(149,5): error TS2322: Type 'Uncapitalize<string>' is not assignable to type '`a${string}`'.


==== tests/cases/conformance/types/literal/stringMappingOverPatternLiterals.ts (29 errors) ====
    // non-template
    type A = "aA";
    type B = Uppercase<A>;
    type C = Lowercase<A>;
    
    // templated
    type ATemplate = `aA${string}`;
    type BTemplate = Uppercase<ATemplate>;
    type CTemplate = Lowercase<ATemplate>;
    
    function f1(
        a: A,
        b: B,
        c: C,
        a_template: ATemplate,
        b_template: BTemplate,
        c_template: CTemplate
    ) {
        // non-template versions should be assignable to templated versions (empty string matches string)
        a_template = a;
        b_template = b;
        c_template = c;
    
        // not the other way around
        a = a_template;
        ~
!!! error TS2322: Type '`aA${string}`' is not assignable to type '"aA"'.
        b = b_template;
        ~
!!! error TS2322: Type '`AA${Uppercase<string>}`' is not assignable to type '"AA"'.
!!! error TS2322:   Type '`AA${string}`' is not assignable to type '"AA"'.
        c = c_template;
        ~
!!! error TS2322: Type '`aa${Lowercase<string>}`' is not assignable to type '"aa"'.
!!! error TS2322:   Type '`aa${string}`' is not assignable to type '"aa"'.
    
        // Additionally, all the template versions should be mutually incompatible (they describe differing sets)
        a_template = b_template;
        ~~~~~~~~~~
!!! error TS2322: Type '`AA${Uppercase<string>}`' is not assignable to type '`aA${string}`'.
        a_template = c_template;
        ~~~~~~~~~~
!!! error TS2322: Type '`aa${Lowercase<string>}`' is not assignable to type '`aA${string}`'.
    
        b_template = a_template;
        ~~~~~~~~~~
!!! error TS2322: Type '`aA${string}`' is not assignable to type '`AA${Uppercase<string>}`'.
        b_template = c_template;
        ~~~~~~~~~~
!!! error TS2322: Type '`aa${Lowercase<string>}`' is not assignable to type '`AA${Uppercase<string>}`'.
    
        c_template = a_template;
        ~~~~~~~~~~
!!! error TS2322: Type '`aA${string}`' is not assignable to type '`aa${Lowercase<string>}`'.
        c_template = b_template;
        ~~~~~~~~~~
!!! error TS2322: Type '`AA${Uppercase<string>}`' is not assignable to type '`aa${Lowercase<string>}`'.
    }
    
    // Raw string mapping assignability
    
    function f2(x1: string, x2: Uppercase<string>, x3: Lowercase<string>) {
        // ok
        x1 = x2;
        x1 = x3;
    
        x2 = "ABC";
        x3 = "abc";
    
        // should fail (sets do not match)
        x2 = x1;
        ~~
!!! error TS2322: Type 'string' is not assignable to type 'Uppercase<string>'.
        x2 = x3;
        ~~
!!! error TS2322: Type 'Lowercase<string>' is not assignable to type 'Uppercase<string>'.
        x3 = x1;
        ~~
!!! error TS2322: Type 'string' is not assignable to type 'Lowercase<string>'.
        x3 = x2;
        ~~
!!! error TS2322: Type 'Uppercase<string>' is not assignable to type 'Lowercase<string>'.
    
        x2 = "AbC";
        ~~
!!! error TS2322: Type 'string' is not assignable to type 'Uppercase<string>'.
        x3 = "AbC";
        ~~
!!! error TS2322: Type 'string' is not assignable to type 'Lowercase<string>'.
    }
    
    // Mappings over mappings
    
    function f3(
        x1: Uppercase<string>,
        x2: Uppercase<Uppercase<string>>,
        x3: Uppercase<Lowercase<string>>) {
    
        // _ideally_ these would all be equivalent
        x1 = x2;
        x1 = x3;
    
        x2 = x1;
        x2 = x3;
    
        // you'd think these were equivalent - the outer `Uppercase` conceptually
        // makes the inner `Lowercase` effectively a noop - but that's not so;
        // the german sharp s makes that not completely true (lowercases to ss,
        // which then uppercases to SS), so arbitrary nestings of mappings make differing sets!
        x3 = x1;
        ~~
!!! error TS2322: Type 'Uppercase<string>' is not assignable to type 'Uppercase<Lowercase<string>>'.
!!! error TS2322:   Type 'string' is not assignable to type 'Lowercase<string>'.
        x3 = x2;
        ~~
!!! error TS2322: Type 'Uppercase<string>' is not assignable to type 'Uppercase<Lowercase<string>>'.
    
        // and this should also not be equivlent to any others
        var x4: Lowercase<Uppercase<string>> = null as any;
        x1 = x4;
        ~~
!!! error TS2322: Type 'Lowercase<Uppercase<string>>' is not assignable to type 'Uppercase<string>'.
        x2 = x4;
        ~~
!!! error TS2322: Type 'Lowercase<Uppercase<string>>' is not assignable to type 'Uppercase<string>'.
        x3 = x4;
        ~~
!!! error TS2322: Type 'Lowercase<Uppercase<string>>' is not assignable to type 'Uppercase<Lowercase<string>>'.
    
        x4 = x1;
        ~~
!!! error TS2322: Type 'Uppercase<string>' is not assignable to type 'Lowercase<Uppercase<string>>'.
        x4 = x2;
        ~~
!!! error TS2322: Type 'Uppercase<string>' is not assignable to type 'Lowercase<Uppercase<string>>'.
        x4 = x3;
        ~~
!!! error TS2322: Type 'Uppercase<Lowercase<string>>' is not assignable to type 'Lowercase<Uppercase<string>>'.
    }
    
    // string mapping over non-string pattern literals is preserved
    
    type NonStringPat = Uppercase<`aA${number}${bigint}${boolean}`>;
    type EquivalentNonStringPat = `AA${Uppercase<`${number}`>}${Uppercase<`${bigint}`>}${Uppercase<`${boolean}`>}`;
    
    function f4(x1: NonStringPat, x2: EquivalentNonStringPat) {
        // Should both work
        x1 = x2;
        x2 = x1;
    }
    
    // Capitalize and uncapitalize on template literals
    
    function f5(
        cap_tem: `A${string}`,
        cap_str: Capitalize<string>,
        cap_tem_map: Capitalize<`A${string}`>,
        cap_tem_map2: Capitalize<`a${string}`>,
        uncap_tem: `a${string}`,
        uncap_str: Uncapitalize<string>,
        uncap_tem_map: Uncapitalize<`A${string}`>,
        uncap_tem_map2: Uncapitalize<`a${string}`>,
    ) {
        // All these are capitalized
        cap_str = cap_tem;
        cap_str = cap_tem_map;
        cap_str = cap_tem_map2;
    
        // these are all equivalent
        cap_tem = cap_tem_map;
        cap_tem = cap_tem_map2;
        cap_tem_map = cap_tem_map2;
        cap_tem_map = cap_tem;
        cap_tem_map2 = cap_tem_map;
        cap_tem_map2 = cap_tem;
    
        // meanwhile, these all require a `A` prefix
        cap_tem = cap_str;
        ~~~~~~~
!!! error TS2322: Type 'Capitalize<string>' is not assignable to type '`A${string}`'.
!!! error TS2322:   Type 'string' is not assignable to type '`A${string}`'.
        cap_tem_map = cap_str;
        ~~~~~~~~~~~
!!! error TS2322: Type 'Capitalize<string>' is not assignable to type '`A${string}`'.
        cap_tem_map2 = cap_str;
        ~~~~~~~~~~~~
!!! error TS2322: Type 'Capitalize<string>' is not assignable to type '`A${string}`'.
    
        // All these are uncapitalized
        uncap_str = uncap_tem;
        uncap_str = uncap_tem_map;
        uncap_str = uncap_tem_map2;
    
        // these are all equivalent
        uncap_tem = uncap_tem_map;
        uncap_tem = uncap_tem_map2;
        uncap_tem_map = uncap_tem_map2;
        uncap_tem_map = uncap_tem;
        uncap_tem_map2 = uncap_tem_map;
        uncap_tem_map2 = uncap_tem;
    
        // meanwhile, these all require a `a` prefix
        uncap_tem = uncap_str;
        ~~~~~~~~~
!!! error TS2322: Type 'Uncapitalize<string>' is not assignable to type '`a${string}`'.
!!! error TS2322:   Type 'string' is not assignable to type '`a${string}`'.
        uncap_tem_map = uncap_str;
        ~~~~~~~~~~~~~
!!! error TS2322: Type 'Uncapitalize<string>' is not assignable to type '`a${string}`'.
        uncap_tem_map2 = uncap_str;
        ~~~~~~~~~~~~~~
!!! error TS2322: Type 'Uncapitalize<string>' is not assignable to type '`a${string}`'.
    }