This repository serves as an introduction to TypeScript. After reading through the documentation and completing the challenges, you should have a basic grasp of how the language works.
VSCode is a great editor for TypeScript. It has great navigation for the language and includes numerous extensions for both JavaScript and Typescript.
Ensure you have npm
installed via Homebrew or via Node.
Then install local packages from the root of the project.
npm install
In the basic-types/
folder, there is some documentation on basic types and data structures. These come from https://www.typescriptlang.org/. Go through each file and experiment with the code.
TypeScript is compiled into JavaScript for both the browser and Node.js. The tsc-playground/
folder contains an index.ts
file that can be compiled into valid JavaScript.
npm run compile-typescript
This command will output an index.js
file. You can play around with different compilation flags. See documentation on that here.
Here's a simple Kata to familiarize yourself with the syntax of the language.
Get all tests passing by removing x
from xit
and running the tests.
npm test gimme-it/
This challenge requires string interpolation and input/return typing for functions.
npm test two-fer/
*Taken from an Exercism challenge
This challenge requires more complex typing.
npm test space-age/
*Taken from an Exercism challenge
This folder contains some basic set up for a potential AWS Lambda written in TypeScript.
The goal is to create a deployable package for an AWS Lambda for a supported Node.js runtime.
Let's imagine there's an endpoint site.com/users/{user_id}
. This is proxied through AWS API Gateway and parsed into an event for AWS Lambda consumption.
The handler
can accept the following event:
{
...
"pathParameters": {
"user_id": "abc123"
}
}
and return the response:
{
"statusCode": 200,
"body": "{\"user\":{\"id\":\"abc123\",\"email\":\"[email protected]\"}}"
}
The following steps are recommended:
- Create a test (TDD!)
- Pass the test
- Hint:
npm test aws-lambda/
- Hint:
- Resolve all required types
- Compile the TypeScript source code
- Hint:
npx tsc
- Hint:
- Zip up the file for AWS
- Hint:
chmod +x .pack_for_aws/run
- Hint: