TypeScript is a superset of JavaScript that adds static typing and class-based object-oriented programming. It allows developers to migrate existing JavaScript code incrementally by adding type annotations and migrating files to the .ts extension over time. The document discusses TypeScript's architecture, transpilation to JavaScript, typing system, and provides recommendations for migrating JavaScript code to TypeScript.
Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
Microsoft Typescript is a statically typed compiled language to clean and a simple plain old JavaScript code which runs on any browser, in Node.js or in any JavaScript engine that supports ECMAScript 3 (or newer).
Presented at Web Unleashed on September 16-17, 2015 in Toronto, Canada
More info at www.fitc.ca/webu
Why TypeScript?
with Jeff Francis
OVERVIEW
TypeScript is a type-checked superset of JavaScript that benefits medium-sized to complex JavaScript projects. Why would you want to learn a new language, instead of another JavaScript framework? You have all this existing JavaScript code, so how can you adopt something new without throwing the old stuff out?
This session is about the benefits of using TypeScript on top of JavaScript in your projects, and demonstrate step by step ways of migrating an existing JavaScript project to TypeScript. We will dive into code generated by the compiler and look at resources and tools that make working in TypeScript a pleasurable experience.
OBJECTIVE
To understand when it’s a good idea to use TypeScript.
TARGET AUDIENCE
JavaScript developers.
ASSUMED AUDIENCE KNOWLEDGE
Intermediate JavaScript experience.
FIVE THINGS AUDIENCE MEMBERS WILL LEARN
The basics of TypeScript – types, classes, modules, and functions
How TypeScript’s design makes getting started simple and helps projects
What compiled TypeScript looks like and how to debug
What tools can help take advantage of TypeScript’s type information
How to migrate a JavaScript project to TypeScript
The session will provide the knowledge about react page life cycle and how more precise actions or operations can be performed using react hooks concepts
Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
Microsoft Typescript is a statically typed compiled language to clean and a simple plain old JavaScript code which runs on any browser, in Node.js or in any JavaScript engine that supports ECMAScript 3 (or newer).
Presented at Web Unleashed on September 16-17, 2015 in Toronto, Canada
More info at www.fitc.ca/webu
Why TypeScript?
with Jeff Francis
OVERVIEW
TypeScript is a type-checked superset of JavaScript that benefits medium-sized to complex JavaScript projects. Why would you want to learn a new language, instead of another JavaScript framework? You have all this existing JavaScript code, so how can you adopt something new without throwing the old stuff out?
This session is about the benefits of using TypeScript on top of JavaScript in your projects, and demonstrate step by step ways of migrating an existing JavaScript project to TypeScript. We will dive into code generated by the compiler and look at resources and tools that make working in TypeScript a pleasurable experience.
OBJECTIVE
To understand when it’s a good idea to use TypeScript.
TARGET AUDIENCE
JavaScript developers.
ASSUMED AUDIENCE KNOWLEDGE
Intermediate JavaScript experience.
FIVE THINGS AUDIENCE MEMBERS WILL LEARN
The basics of TypeScript – types, classes, modules, and functions
How TypeScript’s design makes getting started simple and helps projects
What compiled TypeScript looks like and how to debug
What tools can help take advantage of TypeScript’s type information
How to migrate a JavaScript project to TypeScript
The session will provide the knowledge about react page life cycle and how more precise actions or operations can be performed using react hooks concepts
Just a simple intro to typescript.
Most of the contents are of any OO language, hence slide contents are minimal. If anyone need any further help, reach me out - akhil2369492@gmail.com
-Akhil
Slide 1
TypeScript
* This presentation is to show TypeScript's major feature and the benefit that it brings to your JavaScript projects.
* Our main objective is just to spark interest especially to those not familiar with the tool.
Slide 2
- What is TypeScript
* go to next slide
Slide 3
- Is a superset of JavaScript
* it simply means an extension to JavaScript
- Use JavaScript code on TypeScript
* JS code naturally works on TypeScript
* Which also means your beloved JavaScript libraries such as JQuery, or your fancy interacive plugins would work as well.
- TypeScript compiles to plain old JavaScript
* TS code compiles to simple and clean JS.
Slide 4
- Screenshot of TS compiled to JS
* In this example, compiling a TS class code would result to a JS version, and a regular JavaScript function when compiled is basically untouched.
Slide 5
- TypeScript's Main Feature
* So what does TS provide us with? What does it actually do?
Slide 6
- Static Type Checking
* TypeScript allows us to enable type checking by defining data types to your for ex. variables, function parameters and return types.
Slide 7
- Screenshot of basic Static Type Checking
* In this example…
* What I've done here was to assign supposedly wrong values for what the variables or parameters were meant to hold
* As JavaScript is a dynamic and untyped language these expressions would either fail or be okay when you run it on your browser.
* In TypeScript by enabling static type checking these potential errors are caught earlier (see the red marks on the expressions) and wouldn't even allow you to compile unless these are resolved.
* In addition you can also type arrays and object literals
Slide 8
- Effects of Static Type Checking
* As TS code is statically type-checked a side effect of such...
- Allows IDEs to perform live error checks
- Exposes auto-completion and code hinting
Slide 9
- Screenshot of code hinting
* Say I was coding JQuery on regular JavaScript code there would be no natural way to help me identify its class properties, methods and parameters... except through reading the API documentation or a separate plugin.
* As a result of static type checking this allows IDE's to access these class members as code hints
* So if this was a 3rd party library how much more if you are just referencing your own JavaScript/TypeScript files within your project.
Slide 10
- A few of the other cool features
* That was only the basic feature of TypeScript
* A few of the other cool features are...
Slide 11
- End
TypeScript is a super set of JavaScript. This slide covers the key features of TypeScript including basics of typescript, basic types, Interfaces, Functions, Classes, Generics, Modules.
Introduction to TypeScript, demo ( http://goo.gl/VtE4Vm ), Comparison with couple of popular alternatives. (Sadly layout of the slides are a bit ruined by conversion to SlideShare format - original file: http://goo.gl/eeJgbR )
Introduction to React in combination with Redux. Redux helps you to develop applications in a simple way while having features like time-travel available during development.
Just a simple intro to typescript.
Most of the contents are of any OO language, hence slide contents are minimal. If anyone need any further help, reach me out - akhil2369492@gmail.com
-Akhil
Slide 1
TypeScript
* This presentation is to show TypeScript's major feature and the benefit that it brings to your JavaScript projects.
* Our main objective is just to spark interest especially to those not familiar with the tool.
Slide 2
- What is TypeScript
* go to next slide
Slide 3
- Is a superset of JavaScript
* it simply means an extension to JavaScript
- Use JavaScript code on TypeScript
* JS code naturally works on TypeScript
* Which also means your beloved JavaScript libraries such as JQuery, or your fancy interacive plugins would work as well.
- TypeScript compiles to plain old JavaScript
* TS code compiles to simple and clean JS.
Slide 4
- Screenshot of TS compiled to JS
* In this example, compiling a TS class code would result to a JS version, and a regular JavaScript function when compiled is basically untouched.
Slide 5
- TypeScript's Main Feature
* So what does TS provide us with? What does it actually do?
Slide 6
- Static Type Checking
* TypeScript allows us to enable type checking by defining data types to your for ex. variables, function parameters and return types.
Slide 7
- Screenshot of basic Static Type Checking
* In this example…
* What I've done here was to assign supposedly wrong values for what the variables or parameters were meant to hold
* As JavaScript is a dynamic and untyped language these expressions would either fail or be okay when you run it on your browser.
* In TypeScript by enabling static type checking these potential errors are caught earlier (see the red marks on the expressions) and wouldn't even allow you to compile unless these are resolved.
* In addition you can also type arrays and object literals
Slide 8
- Effects of Static Type Checking
* As TS code is statically type-checked a side effect of such...
- Allows IDEs to perform live error checks
- Exposes auto-completion and code hinting
Slide 9
- Screenshot of code hinting
* Say I was coding JQuery on regular JavaScript code there would be no natural way to help me identify its class properties, methods and parameters... except through reading the API documentation or a separate plugin.
* As a result of static type checking this allows IDE's to access these class members as code hints
* So if this was a 3rd party library how much more if you are just referencing your own JavaScript/TypeScript files within your project.
Slide 10
- A few of the other cool features
* That was only the basic feature of TypeScript
* A few of the other cool features are...
Slide 11
- End
TypeScript is a super set of JavaScript. This slide covers the key features of TypeScript including basics of typescript, basic types, Interfaces, Functions, Classes, Generics, Modules.
Introduction to TypeScript, demo ( http://goo.gl/VtE4Vm ), Comparison with couple of popular alternatives. (Sadly layout of the slides are a bit ruined by conversion to SlideShare format - original file: http://goo.gl/eeJgbR )
Introduction to React in combination with Redux. Redux helps you to develop applications in a simple way while having features like time-travel available during development.
Stuck with your Ruby Programming Assignment. Get 24/7 help from tutors with Phd in the subject. Email us at support@helpwithassignment.com
Reach us at http://www.HelpWithAssignment.com
Get 24/7 Reliable Ruby programming Assignment Help, 100% error free, money back guarantee, Phd level tutors, A grade guarantee, www.HelpwithAssignment.com or email us at support@helpwithassignment.com
This full day course will give you a hands-on, deep dive into React Native. In this course, you will learn how to build cross-platform mobile applications from scratch using Facebook's React Native.
Un problème 10 solutions : Azure Fighterfelixbillon
Au sein de la jungle Azure, il existe beaucoup de produits répondant à une multitude de besoins.
Mais certains produits ont beaucoup de fonctionnalités communes et il devient difficile de les différencier.
Déployer des containers, gérer le trafic réseaux, utiliser une base de données SQL, ... Autant de sujets pour lesquelles il existe plusieurs solutions dans Azure.
À travers ces différentes thématiques, les différents challengers s'affronteront afin de mettre en lumière leurs avantages et faiblesses. Let's Get Ready To Rumble !
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
6. TypeScript in open source world
Visual Studio Code Angular Ionic / Stencil RxJS
NativeScript TensorFlow.js NestJS Vue.js
In progress 👍
7. • Superset of Javascript.
• Made in Microsoft.
• Open source on GitHub.
• 2014 v1.0 -> today v3.2.
• Main features :
• Transpilation -> generates Javascript.
• Typing -> only useful during compilation.
TypeScript ?
8. • No official style guide !
• Maybe coding guidelines on TypeScript’s Github ?
Why this talk ?
25. .ts .js Load byCompilation
.js Load by
Polyfill’s code is execute then
application’s code is loaded
Transpilation ->
Polyfill ->
Transpilation vs Polyfill
27. • Export ES2015
• Import ES2015
• Before : AMD, CommonJS, UMD, System, ES2015.
• Over time there will be only one : ES2015
export class Animal {
// …
}
import { Animal } from "./animal";
Module
29. • Use ES2015 -> transpile if needed.
• To prevent ugly import :
1. In tsconfig.json use aliases path :
2. Don’t forget to also configure this aliases into your bundler’s config file.
3. Result :
import { Animal } from "../../../../../../../core/animal";
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@myProject/utils/*": ["app/utils/*"],
"@myPorject/core/*": ["app/core/*"]
}
}
}
import { Animal } from “@myProject/core/animal";
Module
30. enum Color {
Red,
Blue,
Green
}
let foo: Color = Color.Red;
let bar: string = Color[Color.Red];
"use strict";
var Color;
(function (Color) {
Color[Color["Red"] = 0] = "Red";
Color[Color["Blue"] = 1] = "Blue";
Color[Color["Green"] = 2] = "Green";
})(Color || (Color = {}));
let foo = Color.Red;
let bar = Color[Color.Red];
color.ts TypeScript compiler color.js
Enum
31. const enum Color {
Red,
Blue,
Green
}
let foo: Color = Color.Red;
"use strict";
let foo = 0 /* Red */;
color.ts TypeScript compiler color.js
let bar: string = Color[Color.Red];
Constant Enum
32. • Use const enum as much as possible.
• Be careful with this option :
• If you acces Enum via index, thinks of Map/Set, Object, …
--preserveConstEnums
Enum
33. class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
class PoliteGreeter extends Greeter {
//...
}
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Greeter = /** @class */ (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
}());
var PoliteGreeter = /** @class */ (function (_super) {
__extends(PoliteGreeter, _super);
function PoliteGreeter() {
return _super !== null && _super.apply(this, arguments) || this;
}
return PoliteGreeter;
}(Greeter));
file.ts TypeScript compiler file.js
TypeScript Helper
34. • Many helpers exists :
• Generate in each file where are needed -> increase bundle size !!!
function __assign(t: any, ...sources: any[]): any; // Helper de Object.Assign
function __spread(...args: any[]): any[]; // Helper de l'opérateur spread
//...
TypeScript Helper : the trap
35. • To prevent helpers to proliferate :
1. Install tslib :
2. Use the following compilation options :
3. Once done, TypeScript compiler only imports helpers from tslib
--importHelpers
--noEmitHelpers
npm install tslib
TypeScript Helper
37. Basic typing
• boolean, number, string, array, void, null, undefined, object, any et unknow.
let name: string;
let list: number[] = [1, 2, 3];
function fn(param: boolean): void {
// Do something
}
38. • Use any as less as possible !
• Prefer unknow to any : let myAny : any = "toto" ;
let myUnknown: unknown = "toto";
let foo: string = myAny;
let bar: string = myUnknown;
myAny.mehtod();
myUnknown.mehtod();
Basic typing
39. • Don’t have to type everythings, let TypeScript compiler inference do !
• Reminder : types are useful only during compilation not at runtime !
Basic typing
40. Classe and interface (1/2)
interface Ninja {
nbShuriken: number;
throwShuriken: () => void;
}
let leonardo: Ninja = new NinjaTurtle();
let donatelo: NinjaTutle = new NinjaTurtle();
class NinjaTurtle implements Ninja {
nbShuriken: number;
constructor() {
this.nbShuriken = 6;
}
throwShuriken(): void {
// Throw shuriken
}
}
42. • Union :
• Intersection :
Union and intersection
class Ninja {
nbShuriken: number;
throwShuriken: () => void;
}
class Samurai {
nbKunai: number;
throwKunai: () => void;
}
assign<T, U>(target: T, source: U): T & U;
function throwAttack(human: Ninja | Samurai) {
if (human instanceof Ninja) {
human.throwShuriken();
} else {
human.throwKunai();
}
}
43. Type alias
class Ninja {
nbShuriken: number;
throwShuriken: () => void;
}
class Samurai {
nbKunai: number;
throwKunai: () => void;
}
type Fighter = Ninja | Samurai;
function throwAttack(human: Fighter) {
if (human instanceof Ninja) {
human.throwShuriken();
} else {
human.throwKunai();
}
}
44. • Which one use ?
• Need implementation -> Classe.
• Need union or intersection -> Alias.
• Otherwise -> Interface or Alias, make a choice and stick to it ☺
Classe vs Interface vs Alias
45. class Order {
id: number;
}
class User {
id: number;
name: string;
}
function processOrder(order: Order) {
// Do something
}
const order = new Order();
const user = new User();
processOrder(order);
processOrder(user);
Structural typings vs nominal typings
46. • “On TypeScript’s roadmap !” -> Investigation.
• One of many hack to force nominal typings :
class Order {
private __nominal: void;
id: number;
}
class User {
private __nominal: void;
id: number;
name: string;
}
function processOrder(order: Order) {
// Do something
}
const order = new Order();
const user = new User();
processOrder(order);
processOrder(user);
Do nominal typgins
47. • Compilation option :
• Master option that enable following sub-options :
--strict
--noImplicitAny
--noImplicitThis
--alwaysStrict
--strictNullChecks
--strictFunctionTypes
--strictPropertyInitialization
Enable stricter type checking (1/2)
48. • Enable immediately on new project, by default when use :
• Enable incrementally on existing project :
Enable stricter type checking (1/2)
{
"compilerOptions": {
"strict": true,
// "noImplicitAny": false,
"strictNullChecks": false,
"strictFunctionTypes": false,
"strictPropertyInitialization": false,
"noImplicitThis": false,
"alwaysStrict": false
}
}
tsc --init
51. • Alaway install .d.ts files in devDependencies.
• Specify composition of lib.d.ts file according to the native Javascript
features you use :
Definition file
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"es5",
"es2015.collection",
"es2015.iterable"
]
}
}
57. Conslusion
• Essential to master TypeScript → Compilation options !
• Many subject not addressed :
• Options needed to use react, angular,…
• Mapped type and Conditional type
• …