| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
# Create task file and set execute permission.
mkdir -p task_0/js/
touch ./task_0/js/main.ts
chmod +x ./task_0/js/main.ts
# Create a new node project
touch task_0/package.json
echo '{
"name": "typescript_dependencies",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start-dev": "webpack-dev-server --open",
"build": "webpack",
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/plugin-proposal-export-default-from": "^7.5.2",
"@babel/preset-typescript": "^7.7.2",
"@types/jest": "^24.0.23",
"@typescript-eslint/eslint-plugin": "^2.4.0",
"@typescript-eslint/parser": "^2.4.0",
"clean-webpack-plugin": "^3.0.0",
"fork-ts-checker-webpack-plugin": "^1.5.1",
"html-webpack-plugin": "^3.2.0",
"jest": "^24.9.0",
"source-map": "^0.7.3",
"ts-jest": "^24.1.0",
"ts-loader": "^6.2.0",
"typescript": "^3.6.4",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.2"
}
}' >> task_0/package.json
# Configure eslint.
touch task_0/.eslintrc.js
echo 'module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
},
};' >> task_0/.eslintrc.js
# Configure typescript.
touch task_0/tsconfig.json
echo '{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"allowJs": true,
"moduleResolution": "node"
}
}' >> task_0/tsconfig.json
# Configure webpack.
touch task_0/webpack.config.js
echo 'const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = {
entry: "./js/main.ts",
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
devServer: {
contentBase: "./dist"
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: "Development"
})
],
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist")
}
};
' >> task_0/webpack.config.js
# Change directory to task folder.
cd ./task_0
# Install node packages.
npm i
# Run project.
npm run start-devCreate a directory task_1 and copy these configuration files into this folder: package.json, tsconfig.json, webpack.config.js
Example:
const teacher3: Teacher = {
firstName: 'John',
fullTimeEmployee: false,
lastName: 'Doe',
location: 'London',
contract: false,
};
console.log(teacher3);
// should print
// Object
// contract: false
// firstName: "John"
// fullTimeEmployee: false
// lastName: "Doe"
// location: "London"
# Create task files and set execute permission.
cp -r task_0 task_1Write an interface named Directors that extends Teacher. It requires an attribute named numberOfReports(number)
Example:
const director1: Directors = {
firstName: 'John',
lastName: 'Doe',
location: 'London',
fullTimeEmployee: true,
numberOfReports: 17,
};
console.log(director1);
// should print
// Object
// firstName: "John"
// fullTimeEmployee: true
// lastName: "Doe"
// location: "London"
// numberOfReports: 17
# Create task file and set execute permission.
cp -r task_1 task_2
# Run project
npm run start-devWrite a function printTeacher:
Write an interface for the function named printTeacherFunction.
# Create task file and set execute permission.
cp -r task_2 task_3
# Run project
cd task_3
npm run start-devWrite a Class named StudentClass:
Requirements:
# Create task file and set execute permission.
cp -r task_3 task_4
# Run project
cd task_4
npm run start-devCreate the DirectorInterface interface with the 3 expected methods:
Create the TeacherInterface interface with the 3 expected methods:
Create a class Director that will implement DirectorInterface
Create a class Teacher that will implement TeacherInterface
Create a function createEmployee with the following requirements:
console.log(createEmployee(200));
Teacher
console.log(createEmployee(1000));
Director
console.log(createEmployee('$500'));
Director
# Create task file and set execute permission.
cp -r task_4 task_5
# Run project
cd task_5
npm run start-devWrite a function isDirector:
Write a function executeWork:
Expected result:
executeWork(createEmployee(200)); Getting to work executeWork(createEmployee(1000)); Getting to director tasks
# Create task file and set execute permission.
cp -r task_5 task_6
# Run project
cd task_6
npm run start-devWrite a String literal type named Subjects allowing a variable to have the value Math or History only. Write a function named teachClass:
Expected result:
teachClass('Math');
Teaching Math
teachClass('History');
Teaching History
# Create task file and set execute permission.
cp -r task_6 task_7
# Run project
cd task_7
npm run start-devCreate a directory called task_3 and copy these configuration files into it: package.json, webpack.config.js, tsconfig.json.
The first part of will require that you build an interface and a type. Inside a file named interface.ts:
You are building the next part of the application architecture. The goal is to save the entities to a database. Because of time constraints, you can’t write a connector to the database, and you decided to download a library called crud.js. Copy this file into the task_3/js directory.
Here it is
export function insertRow(row) {
console.log('Insert row', row);
return Math.floor(Math.random() * Math.floor(1000));
}
export function deleteRow(rowId) {
console.log('Delete row id', rowId);
return;
}
export function updateRow(rowId, row) {
console.log(`Update row ${rowId}`, row);
return rowId;
}
Write an ambient file within task_3/js, named crud.d.ts containing the type declarations for each crud function. At the top of the file import RowID and RowElement from interface.ts.
In main.ts
Create an object called row with the type RowElement with the fields set to these values:
firstName: Guillaume lastName: Salva
Create a const variable named newRowID with the type RowID and assign the value the insertRow command.
Next, create a const variable named updatedRow with the type RowElement and update row with an age field set to 23
Finally, call the updateRow and deleteRow commands.
Expected result:
const obj = {firstName: "Guillaume", lastName: "Salva"};
CRUD.insertRow(obj)
// Insert row {firstName: "Guillaume", lastName: "Salva"}
const updatedRow: RowElement = { firstName: "Guillaume", lastName: "Salva", age: 23 };
CRUD.updateRow(newRowID, updatedRow);
// Update row 125 {firstName: "Guillaume", lastName: "Salva", age: 23}
CRUD.deleteRow(125);
// Delete row id 125
Requirements:
# Create task file and set execute permission.
cp -r task_0 task_3
touch task_3/js/interface.ts
chmod +x task_3/js/interface.ts
touch task_3/js/crud.js
chmod +x task_3/crud.js
touch task_3/js/crud.d.ts
chmod +x task_3/crud.d.ts
# Run project
cd task_8
npm run start-devCreate a new directory task_4 and copy the above tsconfig.json and put this package.json in there
{
"name": "task_4",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.4.0",
"@typescript-eslint/parser": "^2.4.0",
"clean-webpack-plugin": "^3.0.0",
"fork-ts-checker-webpack-plugin": "^1.5.1",
"html-webpack-plugin": "^3.2.0",
"ts-loader": "^6.2.0",
"typescript": "^3.6.4",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.2"
}
}
In task_4/js/subjects:
Create a file Teacher.ts and write a Teacher interface in a namespace named Subjects.
Create a file Subject.ts and write a Subject class in the same namespace named Subjects.
Create a file Cpp.ts and make the following modifications in the same namespace.
Create a file React.ts and write a React Class in the same namespace.
Create a file Java.ts and write a Java Class in the same namespace.
# Create task file and set execute permission.
cp -r task_3 task_4
mkdir -p task_4/js/subjects
touch task_4/js/subjects/Cpp.ts task_4/js/subjects/Java.ts task_4/js/subjects/React.ts task_4/js/subjects/Subject.ts task_4/js/subjects/Teacher.ts
# Run project
cd task_4
npm run build# Run project
cd task_4
npm run buildCreate a directory task_5 and copy these configuration files into the root of task_5: package.json, tsconfig.json, webpack.config.js
Create two interfaces MajorCredits and MinorCredits in task_5/js/main.ts:
Create two functions named sumMajorCredits and sumMinorCredits in task_5/js/main.ts:
# Run project
cd task_5
npm run start-devThis project was done by SE. Moses Mwangi. Feel free to get intouch with me;
📱 WhatsApp +254115227963
📧 Email moses.soft.eng@gmail.com
👍 A lot of thanks to ALX-Africa Software Engineering program for the project and learning resources.
| Back | FazBrowse Home | New Git URL |