Bird
Raised Fist0
Typescriptprogramming~5 mins

Re-exporting modules in Typescript - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What does re-exporting modules mean in TypeScript?
Re-exporting modules means exporting something from one module again through another module, so you can gather exports in one place for easier imports.
Click to reveal answer
beginner
How do you re-export all exports from another module?
Use export * from './module'; to re-export everything that the other module exports.
Click to reveal answer
beginner
How can you re-export a specific export from another module?
Use export { name } from './module'; to re-export only the named export.
Click to reveal answer
intermediate
Why use re-exporting in a project?
It helps organize code by creating a single entry point to import many things, making imports cleaner and easier to manage.
Click to reveal answer
intermediate
Can you rename exports while re-exporting? How?
Yes, you can rename exports using export { originalName as newName } from './module';.
Click to reveal answer
Which syntax re-exports all exports from a module named 'utils'?
Aexport * from './utils';
Bimport * from './utils';
Cexport { * } from './utils';
Dimport { * } from './utils';
How do you re-export only the 'calculate' function from 'math.ts'?
Aexport * from './math';
Bimport { calculate } from './math';
Cexport { calculate } from './math';
Dexport calculate from './math';
What is the benefit of re-exporting modules?
ATo rename files automatically
BTo make code run faster
CTo avoid using imports
DTo create a single place to import many exports
Can you rename an export while re-exporting it?
AYes, using 'as' keyword
BNo, renaming is not allowed
COnly if you import first
DOnly for default exports
Which statement is true about re-exporting?
AIt only works with default exports
BIt allows combining exports from multiple modules into one
CIt disables tree shaking
DIt duplicates code in the output
Explain how re-exporting modules works and why it is useful in TypeScript projects.
Think about how you can collect exports from many files into one place.
You got /4 concepts.
    Describe the difference between re-exporting all exports and re-exporting specific exports from a module.
    Consider when you want everything vs. only some parts.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the main purpose of re-exporting modules in TypeScript?
      easy
      A. To organize and simplify imports by sharing exports from one place
      B. To create new variables inside a module
      C. To run code automatically when a module loads
      D. To prevent modules from being imported multiple times

      Solution

      1. Step 1: Understand re-exporting concept

        Re-exporting means exporting items from one module through another to simplify imports.
      2. Step 2: Identify the main benefit

        This helps organize code and makes importing easier by centralizing exports.
      3. Final Answer:

        To organize and simplify imports by sharing exports from one place -> Option A
      4. Quick Check:

        Re-exporting = Simplify imports [OK]
      Hint: Re-exporting centralizes exports for easier imports [OK]
      Common Mistakes:
      • Thinking re-exporting creates new variables
      • Confusing re-exporting with running code
      • Believing it prevents multiple imports
      2. Which of the following is the correct syntax to re-export everything from a module named utils.ts?
      easy
      A. export all from './utils';
      B. export * from './utils';
      C. import * from './utils';
      D. re-export * from './utils';

      Solution

      1. Step 1: Recall correct re-export syntax

        To re-export all exports from a module, use export * from 'module';.
      2. Step 2: Match syntax with options

        export * from './utils'; matches the correct syntax exactly.
      3. Final Answer:

        export * from './utils'; -> Option B
      4. Quick Check:

        Re-export all = export * from [OK]
      Hint: Use 'export * from' to re-export all [OK]
      Common Mistakes:
      • Using 'import * from' instead of 'export * from'
      • Writing 'export all from' which is invalid
      • Using 're-export' keyword which doesn't exist
      3. Given the following files, what will be the output of console.log in main.ts?
      // mathUtils.ts
      export const pi = 3.14;
      export const e = 2.71;
      
      // index.ts
      export { pi } from './mathUtils';
      
      // main.ts
      import { pi, e } from './index';
      console.log(pi, e);
      medium
      A. 3.14 2.71
      B. 3.14 undefined
      C. undefined 2.71
      D. Error: 'e' is not exported from './index'

      Solution

      1. Step 1: Analyze exports in index.ts

        Only pi is re-exported from mathUtils.ts. e is not exported.
      2. Step 2: Check import in main.ts

        Trying to import both pi and e from index.ts causes an error because e is missing.
      3. Final Answer:

        Error: 'e' is not exported from './index' -> Option D
      4. Quick Check:

        Missing export causes import error [OK]
      Hint: Only re-exported items can be imported [OK]
      Common Mistakes:
      • Assuming all original exports are re-exported
      • Expecting undefined instead of error
      • Ignoring missing export errors
      4. Identify the error in this re-exporting code snippet:
      // helpers.ts
      export function greet() { return 'Hello'; }
      
      // index.ts
      export { greet } from './helpers';
      export { greet } from './helpers';
      medium
      A. Duplicate export of 'greet' causes a syntax error
      B. Missing semicolon after export statements
      C. Cannot re-export functions, only variables
      D. No error, code works fine

      Solution

      1. Step 1: Check for duplicate exports

        The code exports greet twice from the same module, causing a duplicate export.
      2. Step 2: Understand TypeScript rules

        Duplicate exports of the same name cause syntax errors because they conflict.
      3. Final Answer:

        Duplicate export of 'greet' causes a syntax error -> Option A
      4. Quick Check:

        Duplicate exports = syntax error [OK]
      Hint: Avoid exporting same name twice in one module [OK]
      Common Mistakes:
      • Ignoring duplicate export errors
      • Thinking missing semicolons cause error
      • Believing functions can't be re-exported
      5. You have two modules: colors.ts exporting red and blue, and shapes.ts exporting circle and square. How can you create a single index.ts that re-exports only red and circle with new names primaryRed and roundShape?
      hard
      A. import { red, circle } from './colors'; export { red as primaryRed, circle as roundShape };
      B. export * from './colors'; export * from './shapes';
      C. export { red as primaryRed } from './colors'; export { circle as roundShape } from './shapes';
      D. export { primaryRed, roundShape } from './colors', './shapes';

      Solution

      1. Step 1: Understand renaming during re-export

        You can rename exports using export { originalName as newName } syntax.
      2. Step 2: Apply to given modules

        Re-export red as primaryRed from colors.ts and circle as roundShape from shapes.ts.
      3. Final Answer:

        export { red as primaryRed } from './colors'; export { circle as roundShape } from './shapes'; -> Option C
      4. Quick Check:

        Rename exports with 'as' keyword [OK]
      Hint: Use 'export { oldName as newName }' to rename exports [OK]
      Common Mistakes:
      • Using import instead of export for re-exporting
      • Trying to export multiple modules in one statement incorrectly
      • Not renaming exports properly
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard