Skip to content

Commit

Permalink
ts-deom
Browse files Browse the repository at this point in the history
  • Loading branch information
zchub committed Jun 3, 2020
1 parent 98f8fc0 commit e146ef9
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ts-demo/base/interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";
exports.__esModule = true;
function getCounter() {
function counter(str) {
}
counter.title = '123';
counter.add = function (str) { };
return counter;
}
var counter = {
title: '123',
add: function (str1) { }
};
var Sub = /** @class */ (function () {
function Sub() {
this.title = 'abc';
}
Sub.prototype.add = function (str) {
console.log(this.title + str);
};
Sub.prototype.decerate = function (num) {
return 1;
};
return Sub;
}());
exports["default"] = {
run: function () {
var sub = new Sub();
sub.add('-1234');
console.error(sub.decerate(1));
}
};
56 changes: 56 additions & 0 deletions ts-demo/base/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
interface Counter{
readonly start: number // 只读
title: string
lable?: string // 可选属性
add(str: string): void // 函数
}

function getCounter(): Counter {
function counter(str: string) {

}
counter.start = 0
counter.title = '123'
counter.add = function (str: string) { }

return counter;
}

let counter: Counter = {
start: 1,
title: '123',
lable: '+',
add: (str1: string)=>{}
}

interface SubCounter extends Counter {
title: string
add(str: string): void
decerate(num: number): number
}

class Sub implements SubCounter{
start = 0
title = 'abc'

add(str: string) {
console.log(this.title + str)
}

decerate(num: number) {
return 1
}
}




export default {
run(){
let sub = new Sub()

sub.add('-1234')

console.error(sub.decerate(1))
}
}
4 changes: 4 additions & 0 deletions ts-demo/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
exports.__esModule = true;
var interface_1 = require("./base/interface");
interface_1["default"].run();
4 changes: 4 additions & 0 deletions ts-demo/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

import main from './base/interface'

main.run()
13 changes: 13 additions & 0 deletions ts-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "ts-demo",
"version": "1.0.0",
"description": "ts 学习 demo",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "tsc main.ts & npm run start",
"start": "node main"
},
"author": "zhangchuan <[email protected]>",
"license": "ISC"
}
19 changes: 19 additions & 0 deletions ts-demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
//"noImplicitAny": false,
//"sourceMap": true,
// "allowJs": true,
//"outDir": "target",
"inlineSourceMap": true
//"inlineSources": true
},
"exclude": [
"node_modules",
"coverage",
"test"
]
}

0 comments on commit e146ef9

Please sign in to comment.