DiscoveryVIP / TypeScript AcademyHelp

Teaching notes and 25 presenter demonstrations

Teach evidence, not completion clicks

Each prepared demo takes about five minutes. Ask for a prediction first, show actual compiler evidence, execute emitted JavaScript, repair the fault and request an independent explanation. Review written answers using the lesson rubric. A passing output case alone is not mastery. Launch a demo in a separate tab; Reset Demo restores its dedicated source.

1. What TypeScript is

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate what typescript is. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["75"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "75"
  ],
  "error": null
}

Closing explanation: TypeScript adds a static type system to JavaScript. A type describes a set of permitted values or operations; number accepts numeric values and rejects a text argument at this call. A compiler checks source before execution and emits JavaScript for the runtime. The annotations on price, quantity and the return value are erased from ordinary emitted code. They do not convert data or validate an incoming network response. Here the same function is visible as TypeScript, emitted JavaScript, actual diagnostics and actual output. Change one argument before experimenting with the function body.

2. Running your first TypeScript program

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate running your first typescript program. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["100"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "100"
  ],
  "error": null
}

Closing explanation: Compile and Run performs two separate steps. The compiler first reports errors and emits JavaScript only when its configured contract permits emission. The execution environment then runs that JavaScript and captures logs or exceptions. A successful compile is not a run, and a successful run covers only the inputs supplied. Keep source, emitted output and diagnostics visible together so a type annotation is not mistaken for a runtime check.

3. Strings

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate strings. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["ALEX"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "ALEX"
  ],
  "error": null
}

Closing explanation: string describes text, including the empty string. Its methods return particular types: trim and toUpperCase return strings, while length is a number property. A string annotation is not a requirement that text be nonempty or an email address. Validate those domain rules separately. The type explorer uses the checker’s actual information at each source position, which can be more specific than a broad annotation in a narrowed context.

4. Inferred variable types

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate inferred variable types. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["15"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "15"
  ],
  "error": null
}

Closing explanation: TypeScript often infers a binding’s type from its initializer. A let initialized with a number can be reassigned another number, but not text. The type explorer reads actual checker types rather than guessing from the spelling of the literal. Inference is not runtime validation and may intentionally widen a value to support later assignments. Inspect the declaration and a reference after control flow separately.

5. Typed arrays

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate typed arrays. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["27"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "27"
  ],
  "error": null
}

Closing explanation: number[] means an array whose elements are numbers. It does not encode its length, and reading an arbitrary index can produce undefined at runtime. noUncheckedIndexedAccess makes that uncertainty explicit for many indexed reads. Mutating methods such as push respect the element contract. Use a tuple when fixed positions have distinct meanings.

6. Readonly arrays

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate readonly arrays. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["10"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "10"
  ],
  "error": null
}

Closing explanation: ReadonlyArray<T> and readonly T[] prevent mutation through that reference at compile time. They do not deeply freeze nested objects or guarantee that another mutable reference cannot change the same array. Functions that only read should accept readonly inputs, which also permits callers with ordinary arrays. To transform, create a new array instead of pushing into the readonly one.

7. Function parameter types

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate function parameter types. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["20"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "20"
  ],
  "error": null
}

Closing explanation: Parameters define what callers may supply. A numeric signature rejects a string before execution, but it does not prove the numeric input is finite, positive or within a domain range. Runtime guards should implement those additional requirements. Keep the error close to the public boundary and test both compile-time misuse and runtime-invalid numbers.

8. Object types

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate object types. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["Notebook: 12"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "Notebook: 12"
  ],
  "error": null
}

Closing explanation: An object type describes required properties and their types rather than a nominal class identity. An object with a compatible structure can satisfy the contract. Property annotations do not construct or validate a runtime object. Excess-property checks on fresh literals catch many mistakes but are not a general guarantee that an object has no extra fields.

9. Creating interfaces

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate creating interfaces. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["Alex: 3"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "Alex: 3"
  ],
  "error": null
}

Closing explanation: An interface names an object-shaped contract and can be reused across variables and functions. It describes the required structure rather than generating a constructor. Interfaces can merge declarations, which is useful in some library scenarios and surprising if names collide. Keep module boundaries explicit and inspect the properties the checker actually sees.

10. Interfaces versus aliases

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate interfaces versus aliases. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["Reviewed"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "Reviewed"
  ],
  "error": null
}

Closing explanation: Both interfaces and aliases can describe object contracts. Aliases also name unions and other expressions; interfaces support extension and declaration merging. Neither is universally better. Prefer a consistent style that fits the API and avoid relying on accidental merging. This example intentionally merges an interface in one module so the final required structure is visible.

11. Union types

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate union types. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["4.0", "READY"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "4.0",
    "READY"
  ],
  "error": null
}

Closing explanation: A union permits values from one of several alternatives. Before narrowing, only operations valid for every alternative are safe. number | string does not mean the value is both simultaneously. Avoid broad unions that permit incoherent application states; discriminated unions often make the relationship clearer. Observe how the checker’s type changes inside each branch.

12. Modeling application states

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate modeling application states. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["HTML, CSS"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "HTML, CSS"
  ],
  "error": null
}

Closing explanation: A state model should make invalid combinations difficult to represent. A loading state should not simultaneously require successful data or a failure message. Discriminated unions express those alternatives and help rendering logic stay aligned. They do not automatically schedule asynchronous work or prevent stale responses; those are runtime design concerns.

13. Narrowing with typeof

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate narrowing with typeof. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["4"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "4"
  ],
  "error": null
}

Closing explanation: typeof checks a runtime primitive category and informs control-flow analysis. Remember that typeof null is "object", so an object check alone is insufficient. A narrowed identifier can have different types at different source positions; the explorer records those actual checker types. Keep the validation condition connected to the value you later use.

14. User-defined type guards

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate user-defined type guards. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["Alex"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "Alex"
  ],
  "error": null
}

Closing explanation: A predicate return such as value is User tells the compiler how a successful check narrows data. TypeScript trusts that predicate signature; it does not prove the implementation actually validates every field. Implement the check using real runtime evidence and test deceptive values. A poorly written guard can compile and still make unsafe claims.

15. Understanding any

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate understanding any. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["HELLO"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "HELLO"
  ],
  "error": null
}

Closing explanation: any largely opts a value out of static checking and allows unsafe operations to spread. It can be useful at a migration boundary, but prefer unknown when a value needs validation. A compiler-clean any program can still call a missing method and throw. This lesson’s runtime counterexample demonstrates why suppressing diagnostics is not the same as making code safe.

16. Understanding void

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate understanding void. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["Saved for review"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "Saved for review"
  ],
  "error": null
}

Closing explanation: void describes a function result the caller is not expected to use. A function with an explicit void return annotation cannot return a useful typed value, while contextual void callback assignability has subtleties: callers may ignore a returned value. Distinguish this static contract from runtime undefined. A log operation is an effect, not a returned calculation result.

17. Generic functions

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate generic functions. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["Alex", "4"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "Alex",
    "4"
  ],
  "error": null
}

Closing explanation: A generic parameter expresses a relationship between inputs and outputs rather than choosing one fixed type. identity<T> returns the same T supplied or inferred by the caller. It is not any: operations inside the function must be valid for the permitted T. Inspect resolved call signatures to see actual inferred arguments and return types.

18. TypeScript classes

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate typescript classes. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["1"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "1"
  ],
  "error": null
}

Closing explanation: A class exists at runtime and can also describe instance types. Fields and methods implement behavior; annotations document and check their contracts. Definite initialization is checked under strict settings. A class is not required for every data shape: a plain interface plus functions is often enough. Compare the emitted class with erased annotations to see which parts survive.

19. The keyof operator

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate the keyof operator. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["Alex"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "Alex"
  ],
  "error": null
}

Closing explanation: keyof produces the permitted property-key union of a type. It is a type-level operation and does not enumerate a runtime object. Combine it with a generic key parameter to preserve the relationship between an object and the selected property’s type. An unchecked string is not automatically a safe key. Validate dynamic external keys before indexing.

20. Partial and Required

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate partial and required. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["{\"name\":\"Alex\",\"age\":31}"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "{\"name\":\"Alex\",\"age\":31}"
  ],
  "error": null
}

Closing explanation: Partial makes every property optional, while Required removes optional modifiers. These utility types transform static relationships and do not fill default values or validate updates. A patch operation should apply only allowed fields and decide what absence means. exactOptionalPropertyTypes can matter when undefined is used explicitly rather than a key being omitted.

21. Imports and exports

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate imports and exports. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["12"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "12"
  ],
  "error": null
}

Closing explanation: Modules create explicit dependencies and scope declarations. Relative imports name project files, while package imports need a resolver and installed implementation. A type-only import can be erased, while a runtime import needs emitted code at execution. The academy checks and bundles relative CommonJS output for its sandbox; exported browser applications include a separate ES-module build.

22. Typed DOM selection

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate typed dom selection. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["Preview ready"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "Preview ready"
  ],
  "error": null
}

Closing explanation: DOM selection can return null and often a general Element. Use a suitable generic where appropriate and a real null check before accessing control-specific fields. An assertion that a selector found an input does not verify the DOM. The Browser preview runs actual emitted code; worker execution has no document. Keep the markup and typed selectors aligned.

23. Typed promises

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate typed promises. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["14"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "14"
  ],
  "error": null
}

Closing explanation: Promise<T> describes a future result, not an already available T. Use await or a callback to access the resolved value, and account for rejection. A promise’s type does not describe all possible error values. The local examples use deterministic fixtures and actual asynchronous JavaScript; no remote request is implied.

24. Understanding compiler diagnostics

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate understanding compiler diagnostics. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["16"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "16"
  ],
  "error": null
}

Closing explanation: A diagnostic has a code, category, source location and message from the actual compiler. Start with the first meaningful cause rather than fixing every downstream message independently. The highlighted source range and checker type table help compare the actual and expected contracts. The academy never replaces compiler feedback with an authored imitation; explanatory text is labeled separately.

25. Planning a typed application

Launch Prepared Demo

Start: Prepared lesson with its primary source, prediction, compiler panels and expected-result contract.

Opening narration: We will investigate planning a typed application. Predict the compiler result separately from the JavaScript behavior.

  1. Read Discover and state a prediction before executing.
  2. Click Compile. Read the first diagnostic or confirm that no diagnostic was produced.
  3. Open Emitted JavaScript and Actual Compiler Type Information. Explain which declarations disappeared.
  4. Click Compile and Run. Compare the actual output with ["[\"Test failure\"]"].
  5. Click Load Repair Exercise. Compile and inspect the actual diagnostic or behavioral failure. Use the three hints progressively.
  6. Repair the source. Click Check My Work. Explain the static/runtime boundary and propose another case.
{
  "diagnostics": [],
  "logs": [
    "[\"Test failure\"]"
  ],
  "error": null
}

Closing explanation: Start with the user’s task, trusted and untrusted inputs, valid states and measurable behavior. A type model should clarify requirements rather than precede all understanding of the problem. Separate compile-time contracts from runtime validation, storage and UI. Write a success case and a failure case before implementation and state which integrations are fixtures.