SlideShare une entreprise Scribd logo
1  sur  32
TypeScript
Write JavaScript the way you really want to
Rūtenis Turčinas - rutenis.turcinas@gmail.com
Author
 Rūtenis Turčinas
 rutenis.turcinas@gmail.com
 https://github.com/rootis/jug-topic-1.git
http://www.typescriptlang.org/Content/TypeScript Language Specification.pdf
Agenda
Specification Integration
BuildClean Code
Questions Thoughts Suggestions
TypeScript. What is it? Do we need it?
 TypeScript is a typed superset of JavaScript that compiles to plain JavaScript
 Made by Microsoft
 Open Source
 Google had plans to release AtScript language, but desided to use TypeScript
 Google and Microsoft are writing the Angular 2 framework in TypeScript
 If your project uses JavaScript – TypeScript would be better
Difference between other languages
 CoffeeScript
 More differences from JavaScript
 You can not use plain JavaScript in *.coffee files
 Dart
 Has an own virtual machine
 Browser manufacturers has no plans to support Dart in the near future
How TypeScript works?
 TypeScript file: test.ts
 > tsc test.ts
 Compiler makes test.js file
 JavaScript file will be executed by browser
 > tsc test.ts –sourcemap
 Compiler makes the same test.js and one more file: test.js.map
 Map file used to map *.js with *.ts file lines (to debug *.ts file instead of *.js)
Hello World!
Data types
 boolean
 number
 string
 Array
 enum
 any (try to avoid it)
 void
Statements, loops, functions
 Simple variable assignment
 var variableName: dataType = value;
 Variable which data type is a function
 var variableName: (paramName: dataType) => returnType = value;
 Complex data type (do not use such data types)
 var person: {name: string; surname: string; age: number,
isMale: () => boolean} = null;
Classes, interfaces, methods
interface UsersGroup {
getLanguage: () => string;
}
class Jug implements UsersGroup {
public getLanguage(): string {
return "Java " + this.getJavaVersionTitle();
}
protected getJavaVersion(): number {
return 1.7;
}
private getJavaVersionTitle(): string {
return "v" + this.getJavaVersion();
}
}
Inheritance, overriding
class KaunasJug extends Jug {
protected getJavaVersion(): number {
return 1.8;
}
}
function printUsersGroupLanguage(usersGroup: UsersGroup): void {
console.log(usersGroup.getLanguage());
}
printUsersGroupLanguage(new Jug());
printUsersGroupLanguage(new KaunasJug());
Overloading
interface UsersGroup {
getLanguage(isUpperCase: boolean): string;
getLanguage(versionPrefix: string): string;
}
class KaunasJug implements UsersGroup {
getLanguage(property?: any): string {
if (typeof property === 'boolean'){
return property ? "JAVA v1.8" : "Java v1.8";
} else if (typeof property === "string") {
return "Java " + property + "1.8";
}
}
}
Generics
function printProperty<T>(property: T): void {
console.log(property);
}
interface UserGroupArray<T extends Language> {
add(... languages: T[]): void;
printAllGroups(): void;
}
Lambdas (use as little as possible)
class JavaUsersGroup {
private city: string;
constructor(city: string) {
this.city = city;
}
public printTitle1(): void {
console.log(this.city + " JUG");
}
public printTitle2 = (): void => {
console.log(this.city + " JUG");
};
}
Modules
module usersGroup {
export class API {
public static init(data: any) {
new ViewModel(data.someJSON);
}
}
class ViewModel {
constructor(jsonDataToLoad: string) {
console.log('Loading...');
}
}
class SomeInnerClass {
}
}
External libraries
 Large API, difficult to use, hard to remember: actions, events, properties, sub
modules...
 For example: using selector you get jQuery object. You want to get it‘s specific
child. Which method to use? Can you use the selector?
 99% of developers would use google. More convenient to use ctrl+space and get
the suggestion:
 And if you try to do something ridiculous – the code won‘t compile:
DefinetlyTyped - *.d.ts
 Declaration file (*.d.ts) describes the library or module
 > tsc --declaration file.ts
declare module usersGroup {
class API {
static init(data: any): void;
}
}
Definition manager - tsd
 LOTS of the *.d.ts files are here: https://github.com/borisyankov/DefinitelyTyped
 But its hard to search and download... Is there a better way?
 > npm install tsd –g
 E.g. you want to use library lodash
 Does it has lodash.d.ts file? Which version?
 > tsd query lodash
 Yes! It exists. We want to download lodash.d.ts file
 > tsd install lodash –save
 Using -save you wil store the information about installed *.d.ts in tsd.json
Libraries without *.d.ts or legacy code
 We are using super secret library...
 In our project exists lots of legacy code...
 But we still want to use TypeScript!
 What to do?
 Need to create declaration file for that library or legacy code (*.d.ts)
interface A_Static {
new(m: any): A_Instance;
st: string;
}
interface A_Instance {
inst: number;
}
declare var A: A_Static;
Dependency management tools
 Internal modules
 External modules: import $ = require('jquery');
 commonJS
 --module commonjs
 AMD - requireJS
 --module amd
How to write TypeScript correctly?
 TypeScript also can be terrible... if its plain JavaScript
 How to prevent it?
 Use simple rules:
 Every variable, property, or function result – must have defined data type
 Never use any data type
 Use same clean code conventions like in server side
Decouple modules
 Most of the times JavaScript logic lives in one place
 Large files tightly coupled in different ways
 Impossible to do refactoring without bugs
 How to solve it?
 Decouple logic to different modules
 Don‘t copy paste, just depend on some module
 Define strict public API for integration with other modules
Single responsibility for every item
 One module/class/method should be responsible just for one thing
 Currently we are trying one approach:
 If length of file is more than 200 lines – we should rethink: is it only
responsible for one thing?
 If length of method is more than 5 lines – we should rethink: is it only
responsible for one thing?
 In our project:
 97% of files have <= 200 lines
 72% of methods have <= 5 lines (in 4 files: ~200, ~180, ~150, ~120)
Hide as much as possible
 Encapsulate code
 Export only public API
 One file - one module
 Except – model entities
 Much easier to refactor hidden code
Try to keep code in first level
 JAVA developers can feel much more convenient by having source code in first
level
 Less complexity
 Easyer to understand and support
OK. But my friend uses SunOS and VIM
for editing source code. Can he..?
 Sure thing!
One more thing… Production needs one
file rather than 3
 For development we want all files: *.ts, *.js, *.js.map
 But for production we want only one: compressed *.js
 You can configure build scripts
 E.g. maven resource filtering
Large project. Lots of code.
How to test it?
 Karma, Jasmine, Mocha, tsJunit, Qjunit, ...
 Karma tests can be binded or decoupled from back end unit tests
 Binded tests can be skipped together with java tests using –DskipTests
 Decoupled tests can be skipped separate from java tests using custom
properties
Minuses in TypeScript
 Eclipse IDE
 After compiler version update your code may be broken...
Questions Thoughts Suggestions

Contenu connexe

Tendances

002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type scriptDmitrii Stoian
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painSander Mak (@Sander_Mak)
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practicesIwan van der Kleijn
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type scriptRemo Jansen
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScriptOffirmo
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponLaurent Duveau
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins Udaya Kumar
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScriptGil Fink
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideNascenia IT
 
TypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationTypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationAndrea Paciolla
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!Alessandro Giorgetti
 

Tendances (20)

002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type script
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
 
TypeScript
TypeScriptTypeScript
TypeScript
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
TypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationTypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript application
 
Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 
TypeScript 2 in action
TypeScript 2 in actionTypeScript 2 in action
TypeScript 2 in action
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 

En vedette

«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21MoscowJS
 
Typescript + Graphql = <3
Typescript + Graphql = <3Typescript + Graphql = <3
Typescript + Graphql = <3felixbillon
 
TypeScript Seminar
TypeScript SeminarTypeScript Seminar
TypeScript SeminarHaim Michael
 
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)Ontico
 
TypeScript: Un lenguaje aburrido para programadores torpes y tristes
TypeScript: Un lenguaje aburrido para programadores torpes y tristesTypeScript: Un lenguaje aburrido para programadores torpes y tristes
TypeScript: Un lenguaje aburrido para programadores torpes y tristesMicael Gallego
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricksOri Calvo
 
Angular 2 - Typescript
Angular 2  - TypescriptAngular 2  - Typescript
Angular 2 - TypescriptNathan Krasney
 
Александр Русаков - TypeScript 2 in action
Александр Русаков - TypeScript 2 in actionАлександр Русаков - TypeScript 2 in action
Александр Русаков - TypeScript 2 in actionMoscowJS
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java DevelopersYakov Fain
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 

En vedette (13)

«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
 
Typescript + Graphql = <3
Typescript + Graphql = <3Typescript + Graphql = <3
Typescript + Graphql = <3
 
TypeScript
TypeScriptTypeScript
TypeScript
 
TypeScript Seminar
TypeScript SeminarTypeScript Seminar
TypeScript Seminar
 
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
 
TypeScript: Un lenguaje aburrido para programadores torpes y tristes
TypeScript: Un lenguaje aburrido para programadores torpes y tristesTypeScript: Un lenguaje aburrido para programadores torpes y tristes
TypeScript: Un lenguaje aburrido para programadores torpes y tristes
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricks
 
Angular 2 - Typescript
Angular 2  - TypescriptAngular 2  - Typescript
Angular 2 - Typescript
 
Александр Русаков - TypeScript 2 in action
Александр Русаков - TypeScript 2 in actionАлександр Русаков - TypeScript 2 in action
Александр Русаков - TypeScript 2 in action
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
TypeScriptで快適javascript
TypeScriptで快適javascriptTypeScriptで快適javascript
TypeScriptで快適javascript
 

Similaire à TypeScript - Silver Bullet for the Full-stack Developers

MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software DevelopmentZeeshan MIrza
 
An Introduction to TypeScript
An Introduction to TypeScriptAn Introduction to TypeScript
An Introduction to TypeScriptWrapPixel
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code維佋 唐
 
Workflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large EnterprisesWorkflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large EnterprisesPuppet
 
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin PiebiakWorkflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin PiebiakNETWAYS
 
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...apidays
 
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other ThingsI Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other ThingsMichael Lange
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James NelsonGWTcon
 
Java programming basics
Java programming basicsJava programming basics
Java programming basicsHamid Ghorbani
 
Easy way to learn Core java full material
Easy way to learn Core java full materialEasy way to learn Core java full material
Easy way to learn Core java full materialSivannarayana Chimata
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGuillaume Laforge
 
Building Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstepBuilding Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstepguest9efd1a1
 
Building Server Applications Using Objective C And Gn Ustep
Building Server Applications Using Objective C And Gn UstepBuilding Server Applications Using Objective C And Gn Ustep
Building Server Applications Using Objective C And Gn Ustepwangii
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxMalla Reddy University
 

Similaire à TypeScript - Silver Bullet for the Full-stack Developers (20)

MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
Android develop guideline
Android develop guidelineAndroid develop guideline
Android develop guideline
 
An Introduction to TypeScript
An Introduction to TypeScriptAn Introduction to TypeScript
An Introduction to TypeScript
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
Workflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large EnterprisesWorkflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large Enterprises
 
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin PiebiakWorkflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak
 
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
 
Type script
Type scriptType script
Type script
 
Nodejs
NodejsNodejs
Nodejs
 
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other ThingsI Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Easy way to learn Core java full material
Easy way to learn Core java full materialEasy way to learn Core java full material
Easy way to learn Core java full material
 
Corejava ratan
Corejava ratanCorejava ratan
Corejava ratan
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
Building Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstepBuilding Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstep
 
Building Server Applications Using Objective C And Gn Ustep
Building Server Applications Using Objective C And Gn UstepBuilding Server Applications Using Objective C And Gn Ustep
Building Server Applications Using Objective C And Gn Ustep
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
 

Dernier

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 

Dernier (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 

TypeScript - Silver Bullet for the Full-stack Developers

  • 1. TypeScript Write JavaScript the way you really want to Rūtenis Turčinas - rutenis.turcinas@gmail.com
  • 2. Author  Rūtenis Turčinas  rutenis.turcinas@gmail.com  https://github.com/rootis/jug-topic-1.git
  • 6. TypeScript. What is it? Do we need it?  TypeScript is a typed superset of JavaScript that compiles to plain JavaScript  Made by Microsoft  Open Source  Google had plans to release AtScript language, but desided to use TypeScript  Google and Microsoft are writing the Angular 2 framework in TypeScript  If your project uses JavaScript – TypeScript would be better
  • 7. Difference between other languages  CoffeeScript  More differences from JavaScript  You can not use plain JavaScript in *.coffee files  Dart  Has an own virtual machine  Browser manufacturers has no plans to support Dart in the near future
  • 8. How TypeScript works?  TypeScript file: test.ts  > tsc test.ts  Compiler makes test.js file  JavaScript file will be executed by browser  > tsc test.ts –sourcemap  Compiler makes the same test.js and one more file: test.js.map  Map file used to map *.js with *.ts file lines (to debug *.ts file instead of *.js)
  • 10. Data types  boolean  number  string  Array  enum  any (try to avoid it)  void
  • 11. Statements, loops, functions  Simple variable assignment  var variableName: dataType = value;  Variable which data type is a function  var variableName: (paramName: dataType) => returnType = value;  Complex data type (do not use such data types)  var person: {name: string; surname: string; age: number, isMale: () => boolean} = null;
  • 12. Classes, interfaces, methods interface UsersGroup { getLanguage: () => string; } class Jug implements UsersGroup { public getLanguage(): string { return "Java " + this.getJavaVersionTitle(); } protected getJavaVersion(): number { return 1.7; } private getJavaVersionTitle(): string { return "v" + this.getJavaVersion(); } }
  • 13. Inheritance, overriding class KaunasJug extends Jug { protected getJavaVersion(): number { return 1.8; } } function printUsersGroupLanguage(usersGroup: UsersGroup): void { console.log(usersGroup.getLanguage()); } printUsersGroupLanguage(new Jug()); printUsersGroupLanguage(new KaunasJug());
  • 14. Overloading interface UsersGroup { getLanguage(isUpperCase: boolean): string; getLanguage(versionPrefix: string): string; } class KaunasJug implements UsersGroup { getLanguage(property?: any): string { if (typeof property === 'boolean'){ return property ? "JAVA v1.8" : "Java v1.8"; } else if (typeof property === "string") { return "Java " + property + "1.8"; } } }
  • 15. Generics function printProperty<T>(property: T): void { console.log(property); } interface UserGroupArray<T extends Language> { add(... languages: T[]): void; printAllGroups(): void; }
  • 16. Lambdas (use as little as possible) class JavaUsersGroup { private city: string; constructor(city: string) { this.city = city; } public printTitle1(): void { console.log(this.city + " JUG"); } public printTitle2 = (): void => { console.log(this.city + " JUG"); }; }
  • 17. Modules module usersGroup { export class API { public static init(data: any) { new ViewModel(data.someJSON); } } class ViewModel { constructor(jsonDataToLoad: string) { console.log('Loading...'); } } class SomeInnerClass { } }
  • 18. External libraries  Large API, difficult to use, hard to remember: actions, events, properties, sub modules...  For example: using selector you get jQuery object. You want to get it‘s specific child. Which method to use? Can you use the selector?  99% of developers would use google. More convenient to use ctrl+space and get the suggestion:  And if you try to do something ridiculous – the code won‘t compile:
  • 19. DefinetlyTyped - *.d.ts  Declaration file (*.d.ts) describes the library or module  > tsc --declaration file.ts declare module usersGroup { class API { static init(data: any): void; } }
  • 20. Definition manager - tsd  LOTS of the *.d.ts files are here: https://github.com/borisyankov/DefinitelyTyped  But its hard to search and download... Is there a better way?  > npm install tsd –g  E.g. you want to use library lodash  Does it has lodash.d.ts file? Which version?  > tsd query lodash  Yes! It exists. We want to download lodash.d.ts file  > tsd install lodash –save  Using -save you wil store the information about installed *.d.ts in tsd.json
  • 21. Libraries without *.d.ts or legacy code  We are using super secret library...  In our project exists lots of legacy code...  But we still want to use TypeScript!  What to do?  Need to create declaration file for that library or legacy code (*.d.ts) interface A_Static { new(m: any): A_Instance; st: string; } interface A_Instance { inst: number; } declare var A: A_Static;
  • 22. Dependency management tools  Internal modules  External modules: import $ = require('jquery');  commonJS  --module commonjs  AMD - requireJS  --module amd
  • 23. How to write TypeScript correctly?  TypeScript also can be terrible... if its plain JavaScript  How to prevent it?  Use simple rules:  Every variable, property, or function result – must have defined data type  Never use any data type  Use same clean code conventions like in server side
  • 24. Decouple modules  Most of the times JavaScript logic lives in one place  Large files tightly coupled in different ways  Impossible to do refactoring without bugs  How to solve it?  Decouple logic to different modules  Don‘t copy paste, just depend on some module  Define strict public API for integration with other modules
  • 25. Single responsibility for every item  One module/class/method should be responsible just for one thing  Currently we are trying one approach:  If length of file is more than 200 lines – we should rethink: is it only responsible for one thing?  If length of method is more than 5 lines – we should rethink: is it only responsible for one thing?  In our project:  97% of files have <= 200 lines  72% of methods have <= 5 lines (in 4 files: ~200, ~180, ~150, ~120)
  • 26. Hide as much as possible  Encapsulate code  Export only public API  One file - one module  Except – model entities  Much easier to refactor hidden code
  • 27. Try to keep code in first level  JAVA developers can feel much more convenient by having source code in first level  Less complexity  Easyer to understand and support
  • 28. OK. But my friend uses SunOS and VIM for editing source code. Can he..?  Sure thing!
  • 29. One more thing… Production needs one file rather than 3  For development we want all files: *.ts, *.js, *.js.map  But for production we want only one: compressed *.js  You can configure build scripts  E.g. maven resource filtering
  • 30. Large project. Lots of code. How to test it?  Karma, Jasmine, Mocha, tsJunit, Qjunit, ...  Karma tests can be binded or decoupled from back end unit tests  Binded tests can be skipped together with java tests using –DskipTests  Decoupled tests can be skipped separate from java tests using custom properties
  • 31. Minuses in TypeScript  Eclipse IDE  After compiler version update your code may be broken...