W3Reference.com
Toggle Menu
Home
Online Rust Compiler
Tutorials
Python Tutorial
Java Tutorial
Rust Tutorial
TypeScript Tutorial
ReactJS Tutorial
HTML & CSS Basics
Docker Containers Guide
Kubernetes Tutorial
Software Design Patterns
Blog
All Posts
TypeScript Fundamentals
Assess your understanding of types,interfaces,and generics in TypeScript.
1. Which of the following is a primitive type in TypeScript?
string
object
array
function
2. Select all valid TypeScript types from the options below.
number
any
unknown
never
maybe
3. TypeScript is a superset of JavaScript.
True
False
4. What is the file extension for TypeScript files?
5. Which keyword declares a block-scoped variable that cannot be reassigned?
let
var
const
static
6. Which are valid ways to define a union type in TypeScript?
string | number
string & number
string | boolean | null
number | undefined
7. The 'any' type in TypeScript enables full type checking for that value.
True
False
8. What keyword creates a custom type alias?
9. What is the return type of a function with no return statement?
void
undefined
never
any
10. Which are built-in TypeScript utility types?
Partial
Readonly
Required
Optional
Pick
11. Interfaces can extend other interfaces using the 'extends' keyword.
True
False
12. What term describes a type that can hold a value or null/undefined?
13. Which correctly annotates a function taking a string and returning a number?
(name: string): number => {}
(name) => number
function(name: string): number {}
Both A and C
14. Differences between 'type' and 'interface' include:
Interfaces can be merged; types cannot
Types can use unions/intersections; interfaces cannot
Interfaces support declaration merging
Types are hoisted; interfaces are not
15. The 'never' type represents values that never occur (e.g., a function that always throws).
True
False
16. What compiler option enables strict type-checking features like strictNullChecks?
17. What type is `const x: [string, number] = ['hi', 5];`?
array
tuple
object
union
18. Valid type assertion syntax in TypeScript:
value as Type
<Type>value
Type(value)
value.type = Type
19. TypeScript code runs directly in browsers without compilation.
True
False
20. Name TypeScript's built-in compiler (abbrev.)
Reset
Answered 0 of 0 — 0 correct