TypeScript for C Developers
Learn TypeScript and the JavaScript runtime from C: values, control flow, callbacks, typed collections, validation and object modules. Build a connected order-processing project and port two source programs.
C and TypeScript side by side
The same program in C and in TypeScript, from the lessons of this course.
Run TypeScript
C compiles translation units and links an executable with a main function. TypeScript instead emits JavaScript executed by Node, and its types are erased. This course introduces JavaScript variables, arrays, objects and functions without assuming prior…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8 9int main(void) {10 printf("Hello, %s!\n", "Ada");11 return 0;12}TypeScript1const name: string = "Ada";2console.log(`Hello, ${name}!`);3export {};Numbers and Conversion
C strtol reports conversion progress through an end pointer and range failures through errno; the caller checks both. JavaScript Number instead can yield NaN, and blank text converts to zero. Explicit conversion and validation replace the C end-pointer checks…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8 9int main(void) {10 const char *text = "12";11 char *end;12 errno = 0;13 long value = strtol(text, &end, 10);14 if (errno || end == text || *end != '\0') return 1;15 printf("%ld\n", value + 3);16 return 0;17}TypeScript1const value: number = Number("12");2console.log(value + 3);3export {};Arrays and Slice
C has no standard array-slice value: pointer-and-length views share storage, while copying elements into another array creates independent slots. JavaScript slice creates a new outer array. Its end bound is excluded, and absent bracket reads return undefined…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8 9int main(void) {10 int values[] = {1, 2, 3, 4};11 int middle[2];12 memcpy(middle, values + 1, sizeof middle);13 printf("[%d,%d]\n", middle[0], middle[1]);14 return 0;15}TypeScript1const values: number[] = [1, 2, 3, 4];2console.log(JSON.stringify(values.slice(1, -1)));3export {};For-of and Array Values
C normally iterates arrays through an index or pointer with an explicit length. JavaScript for-of yields values; for-in enumerates keys and is not a C indexed array loop. Use entries when you need both index and value.
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8 9int main(void) {10 int values[] = {3, -1, 2};11 int total = 0;12 for (size_t i = 0; i < sizeof values / sizeof values[0]; ++i) {13 if (values[i] > 0) total += values[i];14 }15 printf("%d\n", total);16 return 0;17}TypeScript1let total: number = 0;2for (const value of [3, -1, 2]) { if (value > 0) total += value; }3console.log(total);4export {};Truthiness Is Not Emptiness
C collection emptiness is usually represented by an explicit length, not by testing a pointer to its storage. A non-null pointer can accompany zero elements. JavaScript treats an empty array as true. The source nonempty check and target truthiness check…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8 9int main(void) {10 size_t count = 0;11 puts(count > 0 ? "true" : "false");12 return 0;13}TypeScript1const value: unknown = [];2console.log(Boolean(value));3export {};Annotations and Inference
C distinguishes integer and floating-point types, with usual arithmetic conversions governing mixed expressions. TypeScript number uses JavaScript floating-point arithmetic. Annotating a count as number does not provide C integer widths, overflow or division…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8 9int main(void) {10 double price = 2.5;11 int count = 4;12 printf("%g\n", price * count);13 return 0;14}TypeScript1const price: number = 2.5;2const count = 4;3console.log(price * count);4export {};
Syllabus
12 chapters48 lessons1 project48 challenges96 quiz questionsStart Here
1 lessonRuntime Values
4 lessonsRuntime Collections
4 lessonsRuntime Control Flow
4 lessonsRuntime Edge Cases
4 lessonsTyped Contracts
5 lessonsTyped Flow
5 lessonsTyped Functions
5 lessonsTyped Collections
5 lessonsReliable Modules and Objects
5 lessonsProject: Typed Orders
4 lessonsFinal Challenges
2 lessonsFrequently asked questions
Who is TypeScript for C Developers for?
For people who already write C and want to learn TypeScript. Each lesson starts from C you know and shows how TypeScript does the same thing, so you skip the beginner basics.
Do I need to know TypeScript already?
No. The course starts with your first TypeScript program. You need C basics: variables, conditions, loops, functions and collections.
How many lessons does TypeScript for C Developers have?
TypeScript for C Developers contains 48 interactive lessons you can complete at your own pace.
What does TypeScript for C Developers cover?
The course is organized into chapters covering: Start Here, Runtime Values, Runtime Collections, Runtime Control Flow, and more.
Is TypeScript for C Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.