TypeScript Basics 7 - Arrays and tuples

preview_player
Показать описание

Learn how to declare typed arrays in TypeScript. Understand tuples in TypeScript and how to declare and use them.

Course: TypeScript Basics
Learn about the basics of TypeScript. Understand how types work, how to use arrays and tuples, how to declare classes and interfaces. Understand concepts of type erasure, duck typing, enums, generics and modules. Create a development workflow and configure the TypeScript compiler to your needs. And watch as I build an end-to-end TypeScript application from scratch.
Рекомендации по теме
Комментарии
Автор

you can also specify any or without specifying type. it is working

sarathbabu
Автор

how null is data type since if we try this code console.log(typeof null) it would give us "object"?

medi
Автор

ts code :
function f(val1:number) {
console.log(val1);
}

js code, after compile :
function f(val1) {
console.log(val1);
}

Is there any way to maintain type safe even after convert to js from

karthiknedunchezhiyan
Автор

can i use two or more different datatypes in tubles?

prasath
Автор

hi ...one query...var a : undefined;
a = null;
a = undefined;
It doesnt gives any compilation error..

sandeepgarg
Автор

Hi tuple is not working for me, its allowing me to enter any type and any number

nandhakishore
Автор

Hi... I am trying to run below ts code


var notSure : String;
notSure = "maybe a string instead";
console.log(notSure);


Its getting compiled successfully but while executing getting below error:


(function (exports, require, module, __filename, __dirname) { var notSure : String;
^
SyntaxError: Unexpected token :
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile
at Object.Module._extensions..js
at Module.load
at tryModuleLoad
at Function.Module._load
at Function.Module.runMain
at startup


Could you please help me on this.

nihalbidkar
Автор

Tuple doesn't work for me either:


// This does not work


var myArr: [number, string]


myArr = [1, '2'];




// This works


var myArr: [number, number]


myArr = [1, 2];

asmrtist
Автор

var in 2018? please come back from the past

NerveClasp