TypeScript Interview Questions

Practice for TypeScript interviews by solving TestDome questions. Our interview questions are used by more than 5,000 companies and 450,000 individual test takers.

Jobseekers: Certify Your Knowledge

Take a Certification Test

Companies: Use Our Tests for Screening

Buy a Pack Of Candidates

Try to solve 3 TypeScript interview questions below. Hints can help you find answers to questions you are having trouble with.

1. Color Type

Arrays OOP
   
Easy  

The following code initializes three types representing the colors: red, green and blue.

type ColorType = [string, number, number, number];
let red: ColorType = ['Red', 1, 0, 0];
let green: [string, number, number, number] = ['Green', 0, 1, 0];
let blue = ['Blue', 0, 0, 1];

Select the statements that are correct.

(Select all acceptable answers.)

All three colors can have new elements of any type appended to them.
ColorType is an alias to a tuple.
All three colors would compile to the same JavaScript type signature.
ColorType is an array where the type of a fixed number of elements is known.
All three variables are immutable.
   


2. Uppercase Types

OOP Types
   
Easy  

The following code initializes strings as three different types and attempts to make them uppercase. Which statements about the behavior of the typescript compiler are correct?

let stringType: string = "string type";
stringType.toUpperCase();

let anyType: any = "any type";
anyType.toUpper();
anyType.toUpperCase();

let objectType: Object = "object type";
objectType.toUpperCase();

(Select all acceptable answers.)

The typescript compiler confirms that toUpperCase exists on the stringType instance.
The typescript compiler states that toUpper does not exist on the anyType instance;
The typescript compiler confirms that toUpperCase exists on the anyType instance.
The typescript compiler states that the toUpperCase function does not exist on the objectType instance.
The typescript compiler confirms that the toUpperCase function exists on the objectType instance.
   


3. Positionable

Mixins OOP
   
Hard  

Consider the following two base classes, Positionable and Rotatable, and MovingObject derived class:

class Positionable {
    locationX: number;
    locationY: number;
}

class Rotatable {
    orientation: number;
    rotate(orientation: number) {
        this.orientation += orientation;
    }
    align(rotatable: Rotatable) {
        this.orientation = rotatable.orientation;
    }
}

class MovingObject implements Positionable, Rotatable {
    locationX: number = 0;
    locationY: number = 0;
    orientation: number = 0;
    rotate: (orientation: number) => void;
}

applyMixins(MovingObject, [Positionable, Rotatable]);
function applyMixins(derivedCtor: any, baseCtors: any[]) {
    baseCtors.forEach(baseCtor => {
        Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
            derivedCtor.prototype[name] = baseCtor.prototype[name];
        });
    });
}

let mover = new MovingObject(); 
mover.rotate(30);

Select the statements that are correct.

(Select all acceptable answers.)

The applyMixins function applies the implementations of Positionable and Rotatable to MovingObject.
The TypeScript compiler will highlight that the property 'align' is missing for the type MovingObject.
As the MovingObject implements Rotatable, the call to mover.rotate(30) will do nothing.
The Positionable class could be changed to an interface without causing any compiler errors.
The properties of MovingObject are required as stand-ins to satisfy the TypeScript compiler.
   


If you feel ready, take one of our timed public TypeScript Interview Questions tests:
HTML/CSS

HTML/CSS, Angular, TypeScript, and Node.js Online Test (Easy / Hard)

HTML/CSS, Angular, TypeScript, Node.js, and SQL Online Test (Easy / Hard)

Angular

Angular and TypeScript Online Test (Easy / Hard)

TypeScript

TypeScript and JavaScript Online Test (Easy / Hard)

Not exactly what you are looking for? Go to our For Jobseekers section.