SEARCH
You are in browse mode. You must login to use MEMORY

   Log in to start

TypeScript


🇬🇧
In English
Created:
TypeScript


Public
Created by:
John Pencola


0 / 5  (0 ratings)



» To start learning, click login

1 / 25

[Front]


What type will TypeScript infer for "age"?

const age = 6

[Back]


6 

Because the age variable is a const, it is the most specific type TypeScript can associate with it.


Practice Known Questions

Stay up to date with your due questions

Complete 5 questions to enable practice

Exams

Exam: Test your skills

Exam mode unavailable

Learn New Questions

Dynamic Modes

SmartIntelligent mix of all modes
CustomUse settings to weight dynamic modes

Manual Mode [BETA]

Select your own question and answer types
Specific modes

Learn with flashcards

TypeScript - Leaderboard

The course owner has disabled public visibility of the leaderboard for this course.


TypeScript - Details

Levels:

Questions:

27 questions
🇬🇧🇬🇧
What type will TypeScript infer for "age"? const age = 6
6 Because the age variable is a const, it is the most specific type TypeScript can associate with it.
What are the two key parts of Object type definitions?
1. The names of the properties that are (or may be) present 2. The types of those properties
Put into words what an index signature is useful for.
Index signatures are used to describe the type of a key used to retrieve an object when working with dictionaries.
When would a literal type be used?
For allowing an exact value which a string, number, or boolean must have. e.g., const constantString = "Hello World"
What is the basic rule for TypeScript's structural type system?
X is compatible with y if y has at least the same members as x. interface Pet { name: string; } let pet: Pet; // dog's inferred type is { name: string; owner: string; } let dog = { name: "Lassie", owner: "Rudd Weatherwax" }; pet = dog;
What is this type called? type TrafficLight = CanCross | ShouldStop;
Union Remember: it is either a value of type X or of type Y
What is this type called? type Foo = A & B;
Intersection Remember: It is a value that is simultaneously of type A and B
How would you rewrite this function to be generic without using "any"? function identity(arg: any): any { return arg }
By using generic type-parameters function identity<T>(arg: <T>): <T> { return arg }
What issue does TypeScript's excess property checking address?
Throws an error when using an object literal that has a property that does not exist in the type that the function expects, meaning there's no way to safely access the property later on.
What are three ways to fix an error about excess property checking?
1. Remove the excess property 2. Add the property to the function argument type 3. Create a variable to hold the value, and pass the variable (instead of the object literal) into the function
Define a tuple.
A multi-element, ordered data structure, where the position of each item has some special meaning or convention
What is the difference between nominal and structural type systems? Describe how this applies to type checking.
Nominal type systems are about names. Structural ones are about structure or shape. The type equivalence check on a function call checks whether the argument is an instance of a class of a given name if nominal. With structural, it doesn't care about which constructor its argument came from, only whether it has the necessary properties.
How do type aliases help address the complexity of many properties on a type?
1. Define a more meaningful name for the type 2. Declare the particulars of the type in a single place 3. Allows import and export of this type from modules
What are type guards?
Expressions which, when used with a control flow statement (e.g., instanceof), allow us to have a more specific type for a particular value