class Person {
#name: string;
constructor(first: string, last: string = '') {
this.#name = first + last;
}
get name() {
return this.#name;
}
}
class InternalClass {
get type() {
return 'internal';
}
}
export class MyClass extends InternalClass {}
export type { InternalClass };
export * as something from './something'
Suppresses an error on the following line similar to ts-ignore
but produces an error when an error doesn't exist
Promise.all and Promise.race were spreading undefined and
null types in the result array.
Ternaries now check if functions are used in place of a boolean
function myFunc() {}
// TypeScript 3.7 behavior
if (myFunc) {
console.log('hello');
}
// TypeScript 3.9
const a = myFunc ? 'a' : 'b';
awaited is a new type that correctly unravels Promise<T> types
function promiseWrap<T>(value: T): Promise<T> {
return Promise.resolve(value);
}
// type Promise<number>
const value = promiseWrap(1);
// type Promise<Promise<number>>
const wrapped = promiseWrap(Promise.resolve(1));
// type Promise<number>
const unwrapped = async () => await wrapped;
// written with awaited
function promiseWrap<T>(value: awaited T): Promise<awaited T> {
return Promise.resolve(value);
}
// type Promise<number>
const value = promiseWrap(1);
// type Promise<number>
const wrapped = promiseWrap(Promise.resolve(1));
// type number
const unwrapped = async () => await wrapped;