Skip to content

Commit 5f90415

Browse files
authored
Merge pull request #188 from IWANABETHATGUY/fix/template-literal
fix: 🐛 template-literal-type with infer type
2 parents d9c8be8 + a4b1bb6 commit 5f90415

File tree

8 files changed

+163397
-163329
lines changed

8 files changed

+163397
-163329
lines changed

common/corpus/types.txt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,8 @@ type A<B, C> = B extends C
11011101
? `${C}${"" extends C ? "" : "."}${B}`
11021102
: never
11031103
: never
1104-
1104+
type Trim<S extends string> = S extends `${infer R}` ? Trim<R> : S;
11051105
---
1106-
11071106
(program
11081107
(type_alias_declaration
11091108
(type_identifier)
@@ -1138,7 +1137,8 @@ type A<B, C> = B extends C
11381137
(template_literal_type
11391138
(template_type
11401139
(literal_type
1141-
(string (string_fragment))))
1140+
(string
1141+
(string_fragment))))
11421142
(template_type
11431143
(literal_type
11441144
(number)))))
@@ -1166,12 +1166,30 @@ type A<B, C> = B extends C
11661166
(literal_type
11671167
(string))
11681168
(literal_type
1169-
(string (string_fragment)))))
1169+
(string
1170+
(string_fragment)))))
11701171
(template_type
11711172
(type_identifier)))
11721173
(predefined_type))
1173-
(predefined_type))))
1174-
1174+
(predefined_type)))
1175+
(type_alias_declaration
1176+
(type_identifier)
1177+
(type_parameters
1178+
(type_parameter
1179+
(type_identifier)
1180+
(constraint
1181+
(predefined_type))))
1182+
(conditional_type
1183+
(type_identifier)
1184+
(template_literal_type
1185+
(template_type
1186+
(infer_type
1187+
(type_identifier))))
1188+
(generic_type
1189+
(type_identifier)
1190+
(type_arguments
1191+
(type_identifier)))
1192+
(type_identifier))))
11751193
==================================
11761194
Mapped type 'as' clauses
11771195
==================================

common/define-grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ module.exports = function defineGrammar(dialect) {
635635
$.template_literal_type
636636
),
637637

638-
template_type: $ => seq('${',$._primary_type,'}'),
638+
template_type: $ => seq('${',choice($._primary_type, $.infer_type),'}'),
639639

640640
template_literal_type: $ => seq(
641641
'`',

tsx/src/grammar.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8669,8 +8669,17 @@
86698669
"value": "${"
86708670
},
86718671
{
8672-
"type": "SYMBOL",
8673-
"name": "_primary_type"
8672+
"type": "CHOICE",
8673+
"members": [
8674+
{
8675+
"type": "SYMBOL",
8676+
"name": "_primary_type"
8677+
},
8678+
{
8679+
"type": "SYMBOL",
8680+
"name": "infer_type"
8681+
}
8682+
]
86748683
},
86758684
{
86768685
"type": "STRING",

tsx/src/node-types.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5104,6 +5104,10 @@
51045104
{
51055105
"type": "_primary_type",
51065106
"named": true
5107+
},
5108+
{
5109+
"type": "infer_type",
5110+
"named": true
51075111
}
51085112
]
51095113
}

0 commit comments

Comments
 (0)