Skip to content

Commit a69d774

Browse files
committed
type aliases
1 parent 005d499 commit a69d774

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

public/sandbox.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22
// let greet: Function = () => {
33
// console.log('hello, world');
44
// }
5-
// greet = 'hello';
6-
// greet = () => {
7-
// console.log('hello, again');
8-
// }
9-
var add = function (a, b, c /*?*/) {
10-
if (c === void 0) { c /*?*/ = 10; }
11-
console.log(a + b);
12-
console.log(c);
5+
var logDetails = function (uid, item) {
6+
console.log("".concat(item, " has a uid of ").concat(uid));
7+
};
8+
var greet = function (user) {
9+
console.log("".concat(user.name, " says hello"));
1310
};
14-
add(5, 10, 'ninja');
15-
var minus = function (a, b) {
16-
return a + b;
11+
var greetAgain = function (user) {
12+
console.log("".concat(user.name, " says hello again"));
1713
};
18-
var result = minus(10, 7);
19-
console.log(result);

src/sandbox.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
// console.log('hello, again');
99
// }
1010

11-
const add = (a: number, b: number, c/*?*/: number | string = 10): void => {
12-
console.log(a + b);
13-
console.log(c);
14-
}
11+
type StringOrNum = string | number;
12+
type objWithName = { name: string, uid: StringOrNum };
1513

16-
add(5, 10, 'ninja');
14+
const logDetails = (uid: StringOrNum, item: String) => {
15+
console.log(`${item} has a uid of ${uid}`);
16+
}
1717

18-
const minus = (a: number, b: number): number => {
19-
return a + b;
18+
const greet = (user: objWithName) => {
19+
console.log(`${user.name} says hello`);
2020
}
2121

22-
let result = minus(10,7);
23-
console.log(result);
22+
const greetAgain = (user: objWithName) => {
23+
console.log(`${user.name} says hello again`);
24+
}

0 commit comments

Comments
 (0)