From d6fb2dd11c451c2482bd63c2c1842758b46c54dd Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 6 Nov 2019 11:37:16 -0500 Subject: [PATCH] Fooling around with typescript --- tsfun/.gitignore | 1 + tsfun/greeter.js | 14 ++++++++++++++ tsfun/greeter.ts | 23 +++++++++++++++++++++++ tsfun/package.json | 6 ++++++ tsfun/yarn.lock | 8 ++++++++ 5 files changed, 52 insertions(+) create mode 100644 tsfun/.gitignore create mode 100644 tsfun/greeter.js create mode 100644 tsfun/greeter.ts create mode 100644 tsfun/package.json create mode 100644 tsfun/yarn.lock diff --git a/tsfun/.gitignore b/tsfun/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/tsfun/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/tsfun/greeter.js b/tsfun/greeter.js new file mode 100644 index 0000000..0f6d09c --- /dev/null +++ b/tsfun/greeter.js @@ -0,0 +1,14 @@ +var Student = /** @class */ (function () { + function Student(firstName, middleInitial, lastName) { + this.firstName = firstName; + this.middleInitial = middleInitial; + this.lastName = lastName; + this.fullName = firstName + " " + middleInitial + " " + lastName; + } + return Student; +}()); +function greeter(person) { + return "Hello, " + person.firstName + " " + person.lastName; +} +var user = new Student("Jane", "M.", "User"); +console.log(greeter(user)); diff --git a/tsfun/greeter.ts b/tsfun/greeter.ts new file mode 100644 index 0000000..207a02c --- /dev/null +++ b/tsfun/greeter.ts @@ -0,0 +1,23 @@ +class Student { + fullName: string; + constructor( + public firstName: string, + public middleInitial: string, + public lastName: string + ) { + this.fullName = firstName + " " + middleInitial + " " + lastName; + } +} + +interface Person { + firstName: string, + lastName: string; +} + +function greeter(person: Person) { + return "Hello, " + person.firstName + " " + person.lastName; +} + +let user = new Student("Jane", "M.", "User"); + +console.log(greeter(user)); diff --git a/tsfun/package.json b/tsfun/package.json new file mode 100644 index 0000000..8bd48b4 --- /dev/null +++ b/tsfun/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": { + "typescript": "^3.7.2" + }, + "license": "MIT" +} diff --git a/tsfun/yarn.lock b/tsfun/yarn.lock new file mode 100644 index 0000000..230c5be --- /dev/null +++ b/tsfun/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +typescript@^3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb" + integrity sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==