Typescripting yarn

Learning Typescript is not the most fun I’ve had I must admit, but in trying to understand it and admitting it’s usefulness I like to think of it in relation to my greatest (and most expensive!) of hobbies: Knitting.

With a knitting pattern of say, a cardigan, you CAN realistically just jump right to the directions, grab some needles and some yarn and cast on with abandon. You will, at the end of the pattern, have something resembling a cardigan. The pattern works. BUT could you actually wear it? is it proportional? Is it now a doll garment, or something made for a narrow stick with abnormally long arms? Is it maybe stretching the very definition of “cardigan”?

Typescript is bascially the thing in your code that makes sure you are actually getting the cardigan as advertised. You use it to make sure the yarn is actually of the type you need for the pattern to work. For example your pattern calls for a worsted weight yarn, so you actually WANT it to stop you if you try to do it with, say, a very fine mohair. And your knitting needles should also be of a certain size, but within an accepted range appropriate for the yarn and your tension.

type PatternProps = {
Yarn: “Worsted”| “DK” ;
Needles: 4 | 4.5 | 5 | 5.5;
}

Basic and useful.

Leave a comment