Part of Web Development - ISMIN 2023
Course followed by students of Mines St Etienne, ISMIN - M2 Computer Science.
TP1: Introduction to TypeScript
📝 Goal
The goal is to discover TypeScript and its ecosystem by implementing:
-
📙 A
Book
interface containing 4 string attributes:isbn
: International Standard Book Numbertitle
: Title of the bookauthor
: Author of the bookdate
: Date of publication of the book
-
📚 A
Bookshelf
class that internally store books and have the following public functions:addBook(book: Book)
getBook(isbn: string)
returning aBook
getBooksOf(author: string)
returning an array ofBook
sgetAllBooks()
returning an array ofBook
sgetTotalNumberOfBooks()
returning a number
To guide you and help you find out if everything is ✅ a test suite is available in ./Bookshelf.test.ts
.
These tests can be run using Jest in command line or inside your IDE.
🚀 Getting Started
Open a terminal, go to the directory of this TP and run the following commands:
# This will install all needed dependencies
npm install
# This will run the tests once
npm run test
OR
# This will run the tests everytime a change is made in the source code
npm run test:watch
# This will build the source and put the transpiled code in `/dist` directory
npm run build
That's it! You can code!
🛰 Extra:
- Use template literal types to create a type representing an ISBN-13 field and use it for the
isbn
attribute ofBook
- Add a test, and a function
getBooksPublishedAfter(aDate: string)
returning an array ofBook
s
🔑 Solution
An implementation of the TP is available on solution
branch. To switch to the solution just do:
# Commit or revert your local changes
# git add . && git commit -m "YOUR_MSG"
# Update your repository
git pull
# Switch to `solution` branch
git checkout solution