45 mins

Step 3: Type & Interface definitions

3. Type & Interface definitions

Define interface contracts modeling transaction objects and financial categories.

Detailed Implementation Steps:

Create /src/types.ts. Declare an interface named Transaction. It must contain the following keys and types: id (string), amount (number), type (a union literal type limiting values to 'credit' or 'debit'), category (string), and timestamp (Date).

Create a custom type representing user roles (e.g. 'guest', 'user', 'manager'). Implement a type guard function checking if an object satisfies the Transaction interface structure.

Verification Checklist:

  1. Verify compilation fails if declaring transaction records missing one of the interface properties.

Knowledge Check

Ready to test your understanding of Step 3: Type & Interface definitions?

No Quiz Available
Back