Any and Unknown

The course is part of this learning path

Start course

This module will introduce you to Simple Types in TypeScript. You’ll learn about Arrays, Tuples, and Type Assertion, too.

Learning Objectives

The objectives of this module are to provide you with an understanding of:

  • What Simple Types are
  • How to use Arrays
  • How to use Tuples
  • How to use Type Assertion

Intended Audience

This learning path is aimed at all who wish to learn how to use TypeScript.


It is essential you understand the face of contemporary web development to attend this course. You should have a good working knowledge of Javascript. Please note: Before attending this class delegates must have a Microsoft account (signing up one is free).


We welcome all feedback and suggestions - please contact us at to let us know what you think.


So what if we want to bypass type checking on our TypeScript code and more importantly, can we express that we don't mind what type is received. One option would be to emit any TypeScript notation at all, but that isn't very explicit. The any type allows the explicit bypassing of type checking. Literally any type can be stored in the variable without causing an assignment error. This may be useful if we have an array or two that we want to have a value in, but we aren't first what type that value is. As you can see here on line six, we've decoded an array with a type of any. So values of any type can be used anywhere in the array. We've also got a two pole that expects the first four elements to be of the divine type and then an optional Lanie, which is an object on declaration. If we have a final optional element of type any, we can then push any type to the end of the two pole as long as the defined types are satisfied. This is because any appears in the original list of allowed types for the two pole. The unknown type is a type safe counterpart of any. Any value is assignable to a variable with the type unknown but unknown isn't assignable to anything but itself and any. Without using type assertion, or control flow based narrowing. We'll look at type assertion later and control flow based narrowing in a moment. To demonstrate what we mean, we have a variable called unknown value its been declared as type unknown without being assigned. In the following lines, we can assign and reassign its value, to absolutely any value we want. You could also define an initial value for an unknown, as shown online 19. what you can't do is perform any operations, or access any properties within TypeScript on an unknown variable, without doing type assertion or narrowing. On line 21 we can't access the length property of another unknown as TypeScript shut can't be sure, that another unknown has that property. Narrowing involves the use of the instanceof, an instance of operators or custom type guard functions. This is how controlled flow based type analysis is done. We can pass argument to a function that can be of the type unknown, and then have logic inside it, either using typeof to check for primitives or instanceof to find out if the data is an instanceof a particular class to respond appropriately. We have a stringy five function that will check for a number type and converted to a string before returning the value. If the data is not of type number, it will check to see if it's an instance of the date class and convert this to a string using date functions so that we always get a string returned. The function returns the value past to JavaScript's string class. If the two conditions we've specified were not met. If the type of an instanceof operators don't give you the checks you need, you can write a custom guard function. We'll leave you to search online for examples of these.


Simple Types: An Introduction - Arrays - Tuples - Null and Unidentified - Function Arguments and Return Types - Enums - Type Assertion 

About the Author
Learning Paths

Ed is an Outstanding Trainer in Software Development, with a passion for technology and its uses and holding more than 10 years’ experience.

Previous roles have included being a Delivery Manager, Trainer, ICT teacher, and Head of Department. Ed continues to develop existing and new courses, primarily in web design using: PHP, JavaScript, HTML, CSS, SQL, and OOP (Java), Programming Foundations (Python), and DevOps (Git, CI/CD, etc). Ed describes himself as practically minded, a quick learner, and a problem solver who pays great attention to detail. 

Ed’s specialist area is training in Emerging Technologies, within Web Development. Ed mainly delivers courses in JavaScript covering vanilla JS, ES2015+, TypeScript, Angular, and React (the latter is authored by Ed) and has delivered on behalf of Google for PWAs. Ed has also developed a new suite of PHP courses and has extensive experience with HTML/CSS and MySQL. 

Ed is responsible for delivering QA’s Programming Foundations course using the Eclipse IDE. His skillset extends into the DevOps sphere, where he is able to deliver courses based around Agile/Scrum practices, version control, and CI/CD.

Covered Topics