Skip to content

Instantly share code, notes, and snippets.

View dsebastien's full-sized avatar

Sebastien Dubois dsebastien

View GitHub Profile
const p1 = new Promise<Promise<Number>>((resolveOuter) => {
const innerPromise = new Promise<Number>((resolveInner) => {
console.log('Resolving inner promise')
resolveInner(1)
})
console.log('Resolving outer promise')
resolveOuter(innerPromise)
})
// constraints
exists type Foo extends { hello: string };
// type parameters
exists type Foo<T>;
// both!
exists type Foo<T, U> extends { toString(): string };
exists type Foo extends {
hello: string
};
// works!
type Foo = {
hello: string;
world: number;
};
exists type Bar extends {
hello: string;
}
// error!
type Bar = {
hello: number; // <- wrong implementation of 'hello'
world: number;
}
const nestedPromise = new Promise(
(r1) => r1(new Promise(
(r2) => r2(new Promise(
(r3) => r3(42)
)))));
nestedPromise.then((x) => console.log(x)); //prints 42
console.log(await nestedPromise); //prints 42
try {
throw 42;
} catch (err: unknown) { // Error: TS1196: Catch clause variable cannot have a type annotation
console.error("oops");
}
$ echo "Hello world" > hello.txt
dsebastien@trankillux MINGW64 /c/Users/dsebastien/wks/tmp (master)
$ cat hello.txt
Hello world
dsebastien@trankillux MINGW64 /c/Users/dsebastien/wks/tmp (master)
$ ls
total 21K
drwxr-xr-x 1 dsebastien 197121 0 May 19 10:05 .
$ git status
On branch master
No commits yet
Untracked files:
hello.txt
nothing added to commit but untracked files present
$ git status
On branch master
No commits yet
Changes to be committed:
new file: hello.txt
$ echo "I am a Git newcomer" > hello.txt
$ git status
On branch master
No commits yet
Changes to be committed:
new file: hello.txt
Changes not staged for commit: