From 724f623cf1e655ce7d7434e554c296cd037be057 Mon Sep 17 00:00:00 2001 From: thrialectics <203729272+thrialectics@users.noreply.github.com> Date: Wed, 28 Jan 2026 17:45:35 -0500 Subject: [PATCH] Complete computer science Typescript section --- computer-science/typescript/answers/marianne.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 computer-science/typescript/answers/marianne.md diff --git a/computer-science/typescript/answers/marianne.md b/computer-science/typescript/answers/marianne.md new file mode 100644 index 0000000..6fdee26 --- /dev/null +++ b/computer-science/typescript/answers/marianne.md @@ -0,0 +1,14 @@ +What is the difference between typescript and javascript? Why would you use typescript over javascript? + A. TypeScript is JavaScript with static typing added; declare what types variables, parameters, and return values should be. You use TypeScript for larger codebases where you need to catch bugs early, better autocomplete, and self-documenting code. +What are the base types used in typescript? + A. string, number, boolean, null, undefined, void (for functions that don't return), any (opt out of type checking), unknown (safer version of any), never (for functions that never return), plus arrays (string[]) and tuples ([string, number]). +What is a generic? + A. A way to write reusable code that works with multiple types while still being type-safe. Instead of hardcoding a type, you use a placeholder like that gets filled in when the function/class is used. Example: function identity(arg: T): T { return arg; } works for any type. +What is the difference between an interface and a type? + A. Both determine the shape of an object. "Shape" = what properties an object has and what types those properties are. Interfaces are extendable and are generally preferred for object shapes. Types are more flexible and can represent unions, intersections, primitives, etc. For objects, they're mostly interchangeable; use interfaces unless you need type's extra capabilities. +What is a javascript or typescript module? What is a class? + A. A module is a file that exports code (functions, variables, classes) for other files to import - it's how you organize and share code across a project. A class is a blueprint for creating objects with shared properties and methods - it bundles data and behavior together (object-oriented programming). + +// Advanced // +What is type narrowing? + A. When TypeScript automatically refines a variable's type based on control flow. Example: if you check if (typeof x === "string"), inside that block TypeScript knows x is a string, not string | number. It "narrows" the type from broad to specific based on your checks. \ No newline at end of file