0
0
Typescriptprogramming~5 mins

Declaring modules in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a module in TypeScript?
A module is a file that contains code (variables, functions, classes) and can export or import them to share with other files.
Click to reveal answer
beginner
How do you declare a module in TypeScript?
You declare a module by creating a file and using export to share parts of the code, and import to use code from other modules.
Click to reveal answer
intermediate
What is the difference between a global script and a module in TypeScript?
A global script shares variables globally without imports/exports. A module has its own scope and shares code only through exports and imports.
Click to reveal answer
intermediate
What does the declare module syntax do in TypeScript?
It tells TypeScript about the shape of a module that exists elsewhere, often used to describe modules without TypeScript code (like JavaScript libraries).
Click to reveal answer
beginner
How do you export a function named greet from a module?
Use <code>export function greet() { ... }</code> to make the function available to other modules.
Click to reveal answer
Which keyword is used to share code from a TypeScript module?
Aexport
Bshare
Cinclude
Dmodule
How do you use code from another module in TypeScript?
Aimport
Brequire
Cinclude
Duse
What does declare module 'xyz' do?
ARuns the module 'xyz'
BImports the module named 'xyz'
CDefines the shape of an external module for TypeScript
DExports all code from module 'xyz'
Which of these is true about modules in TypeScript?
AModules are the same as classes
BModules share variables globally by default
CModules cannot export functions
DModules have their own scope
What file extension is typically used for a TypeScript module?
A.js
B.ts
C.json
D.tsx
Explain how to declare and use a module in TypeScript.
Think about how you share and use code between files.
You got /4 concepts.
    Describe the purpose of the declare module statement in TypeScript.
    It helps TypeScript know about modules without code.
    You got /4 concepts.