I choose this topic because i wanted to know more about it, how it works and why developers choose to follow this style than our normal JavaScript style. Also to help me understand and do the coding for the duck simulator in typescript on design pattern.
TypeScript starts from the same syntax and semantics that millions of JavaScript developers know today. Use existing JavaScript code, incorporate popular JavaScript libraries, and call TypeScript code from JavaScript.
TypeScript compiles to clean, simple JavaScript code which runs on any browser, in Node.js, or in any JavaScript engine that supports ECMAScript 3 (or newer).
Types enable JavaScript developers to use highly-productive development tools and practices like static checking and code refactoring when developing JavaScript applications.
Types are optional, and type inference allows a few type annotations to make a big difference to the static verification of your code. Types let you define interfaces between software components and gain insights into the behavior of existing JavaScript libraries.
TypeScript offers support for the latest and evolving JavaScript features, including those from ECMAScript 2015 and future proposals, like async functions and decorators, to help build robust components.
These features are available at development time for high-confidence app development, but are compiled into simple JavaScript that targets ECMAScript 3 (or newer) environments.
Examples of typescript
The global variable
foo
contains the number of widgets present.
Code
console.log("Half the number of widgets is " + (foo / 2));
Declaration
Use declare var
to declare variables. If the variable is read-only, you can use declare const
. You can also use declare let
if the variable is block-scoped.
/** The number of widgets present */
declare var foo: number;
Global Functions
Documentation
You can call the function
greet
with a string to show a greeting to the user.
Code
greet("hello, world");
Declaration
Use declare function
to declare functions.
declare function greet(greeting: string): void;
Objects with Properties
Documentation
The global variable
myLib
has a functionmakeGreeting
for creating greetings, and a propertynumberOfGreetings
indicating the number of greetings made so far.
Code
let result = myLib.makeGreeting("hello, world");
console.log("The computed greeting is:" + result);
let count = myLib.numberOfGreetings;
Declaration
Use declare namespace
to describe types or values accessed by dotted notation.
declare namespace myLib {
function makeGreeting(s: string): string;
let numberOfGreetings: number;
}
After learning and observing. I found out that this is way better than then normal javascipting coding. The reason why is say that is because with the typescript , i kind of like dealing with class (objects) like java coding which makes it easier for me. I like how things are organized and it also readable. I guess with this my coding will be javascript/typescript will be fun and cleaned. I really hope pupils enjoy this post and also research more about typescript.
link :: https://www.typescriptlang.org/
https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html
From the blog CS@worcester – Site Title by Derek Odame and used with permission of the author. All other rights reserved by the author.