Loading topic
${} syntax as a runtime template string, but it describes a set of strings the compiler will accept. This chapter covers the syntax, how the compiler decides whether a string matches, and the edge cases5 min readextends constraints, and that you know string literal types, unions, and the template literal syntax from the previous chapters. It uses conditional types with infer only in two short examples, and it explains them as they appear.6 min read${} template literal type syntax from the earlier chapters. Here we look at what the placeholder positions accept, how TypeScript decides whether a string belongs to a5 min readT extends U ? X : Y), generics with extends constraints, and the template literal syntax from the earlier chapters. You will use infer inside a template literal type to pull pieces out of a string type. Then you will learn the matching rules tha5 min readas clause, and a template literal type. It assumes you know basic type aliases, generics with constraints, union types, and mapped types such as { [K in keyof T]: T[K] }. It also assumes you have r5 min readCapitalize and the other case helpers, infer inside template patterns, and mapped types with as clauses. This chapter combines them into three patterns you will meet in real code:6 min readinfer inside a template literal type to pull one piece out of a string type. This chapter combines that with recursion. A recursive type can walk a string of any length and produce a tuple, another string, or an object type.6 min readinfer. It also assumes you know mapped types and recursive conditional types. Here you learn where those tools break down: the compiler refuses a type, slows down, or accepts strings you did not mean to allow.6 min read