TypeScript Helloworld

TypeScript配置入门实例。
https://github.com/prufeng/hellowork-js/tree/master/typescript

1. Install TypeScript

npm install -g typescript

tsc --version
tsc --help

2. Helloworld

2.1 New test.ts

class Startup {
    public static main(): number {
        let date = new Date();
        console.log('Hello World at ' + date.toLocaleString());
        return 0;
    }
}

Startup.main();

2.2 Test in Command Line

tsc test.ts
node test.js

Test done, console output: Hello World

3. TypeScript Project

3.1 tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true
  }
}

Parameters’ options please refer to:
https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
https://www.typescriptlang.org/docs/handbook/compiler-options.html

3.2 Build project

tsc -p .

The test.ts has been compiled to dist/out-tsc/

test.js   
test.js.map 

4. Work with VSCode

4.1 Run Build Task(Ctrl + Shift + B)

Select tsc:build-tsconfig.json, compile the project.
Select tsc:watch-tsconfig.json, will start a watch job in terminal to compile the project files automately when they are modified.

4.2 Debug(F5)

Set main module or start scripts in package.json, then can run with F5 in VS Code.
e.g.

"main": "test.js"

More details please refer to:
https://code.visualstudio.com/Docs/languages/typescript

目录:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python: ``` print("Hello, World!") ``` Java: ``` public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } ``` C++: ``` #include <iostream> using namespace std; int main() { cout << "Hello, World!"; return 0; } ``` C: ``` #include <stdio.h> int main() { printf("Hello, World!"); return 0; } ``` JavaScript: ``` console.log("Hello, World!"); ``` PHP: ``` <?php echo "Hello, World!"; ?> ``` Swift: ``` print("Hello, World!") ``` Ruby: ``` puts "Hello, World!" ``` Go: ``` package main import "fmt" func main() { fmt.Println("Hello, World!") } ``` Perl: ``` print "Hello, World!\n"; ``` R: ``` cat("Hello, World!") ``` Scala: ``` object HelloWorld { def main(args: Array[String]): Unit = { println("Hello, World!") } } ``` Kotlin: ``` fun main() { println("Hello, World!") } ``` Lua: ``` print("Hello, World!") ``` Objective-C: ``` #import <Foundation/Foundation.h> int main() { NSLog(@"Hello, World!"); return 0; } ``` C#: ``` using System; public class HelloWorld { public static void Main(string[] args) { Console.WriteLine("Hello, World!"); } } ``` VB.NET: ``` Module HelloWorld Sub Main() Console.WriteLine("Hello, World!") End Sub End Module ``` SQL: ``` SELECT 'Hello, World!' ``` BASH: ``` echo "Hello, World!" ``` PowerShell: ``` Write-Host "Hello, World!" ``` Batch: ``` @echo off echo Hello, World! ``` Haskell: ``` main = putStrLn "Hello, World!" ``` Rust: ``` fn main() { println!("Hello, World!"); } ``` Dart: ``` void main() { print('Hello, World!'); } ``` Elixir: ``` IO.puts "Hello, World!" ``` Scala: ``` object HelloWorld { def main(args: Array[String]): Unit = { println("Hello, World!") } } ``` Julia: ``` println("Hello, World!") ``` TypeScript: ``` console.log("Hello, World!"); ``` CoffeeScript: ``` console.log "Hello, World!" ``` Pascal: ``` program HelloWorld; begin writeln('Hello, World!'); end. ``` Fortran: ``` program hello print *, "Hello, World!" end program hello ``` Lisp: ``` (print "Hello, World!") ``` F#: ``` [<EntryPoint>] let main argv = printfn "Hello, World!" 0 // return an integer exit code ``` Ada: ``` with Ada.Text_IO; use Ada.Text_IO; procedure Hello is begin Put_Line ("Hello, World!"); end Hello; ``` Racket: ``` #lang racket (displayln "Hello, World!") ``` Clojure: ``` (println "Hello, World!") ``` OCaml: ``` print_endline "Hello, World!" ``` Smalltalk: ``` Transcript show: 'Hello, World!'. ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值