exercism configure --token=exercism configure --token=<your-api-token>
and then download using exercism download --exercise=<exercise-slug> --track=<track-slug>
yarn install
in the directorytype
to commonjs
in the package.json
- described here and probably herenpx tsc *.ts; node <filename.js>
exercism submit <implementation_file_paths>
npm install -g typescript
npx tsc --init
to generate the tsconfig.jsonnpm i @types/mocha
, also this page suggests adding them to types
in tsconfig.jsonnpx tsc <filename>
will convert a .ts
to a .js
require
on vscode that had to be resolved by: npm i -D @types/node
node
to the types
in tsconfig.jsonSyntax | Description |
---|---|
Header | Title |
Paragraph | Text |
this is <html>code
Files:
.nvmrc
index.ts
package.json
containing typescriptcommands:
echo v14.4.0 > .nvmrc
nvm use
npm init
test command: mocha
if you want to then run npm install mocha
npm install chai
npm install typescript
npx tsc <filename>
hello-world.test.ts:
import { helloworld } from './helloworld'
import { expect } from 'chai'
describe('helloworld', () => {
it('should return hi there', () => {
expect(helloworld()).to.equal('hi there')
})
})
hello-world.ts:
export const hithere = () : string => {
return "hi there"
}
TypeScript is a syntactical superset of JavaScript and adds optional static typing to the language. TS transpiles to JS.
TS | JS |
---|---|
Static Typing: types and interfaces | Dynamically typed |
Object Oriented | Prototype-Based Object Orientation |
Transpiles to JS | Just-In-time Compilation |
number
,boolean
,string
Arrays
, Enums
, void
Tuple
, Union
, never
and any
.d.ts
function id<T>(x: T): T {
function successor(n: number | bigint): number
type Heading = {
text: string;
subheadings: Array<Heading>;
}
const heading: Heading = {text: "Welcome to Akalabeth, world of doom!", subheadings: []}
.d.ts
file. Similar to a header file from Cdeclare namespace arithmetics {
add(left: number, right: number): number;
subtract(left: number, right: number): number;
multiply(left: number, right: number): number;
divide(left: number, right: number): number;
}
var employee: [number, string] = [1, "Steve"];
var employee: [number, string][];
There isn't the same as a javascript object which can take obj['i'] - this is covered by interfaces, in object index signatures
interface nucleoTideMap { [index: string]: string }
const dnaToRna: nucleoTideMap = { 'g':'c','c':'g','t':'a','a':'u'}
.map
function whereas map on an array works on every element, on an option it only operates on the value if the value is not null/undefinedfold
which operates only on a value, or getOrElse
which supplies a default valuehttps://www.damirscorner.com/blog/posts/20180216-VariableNumberOfArgumentsInTypescript.html
TS supports ECMAscript 2015 classes syntax.
class ABC {
name: string;
}
const abc = new ABC()