The await
operator can be used to chain async functions calls in a more elegant way. It is formed by a slim arrow (->
), in place of the property accessor operator .
.
Example :
const promiseResult = foo->bar();
const promiseResult = (await foo.bar());
The await
operator is wrapped in parenthesis to allow chained call.
const promiseResult = foo->bar().baz()->qux();
const promiseResult = (await (await foo.bar()).baz().qux());
It can be used on any methods returning a promise, or any promise object property, but due to the javascript behavior of the await
operator, any non-promise return value or property is valid too (but disencouraged, see tslint rule).
Because it is used in place of the property accessor operator .
, it can't be used to await a promise variable.
const foo = bar?.qux;
const baz = quux?.boot++
const foo = (isNil(bar) ? bar.qux : bar);
const baz = (isNil(quux) ? quux.boot++ : quux);
This feature is composed of a marker on the interface to define the type guard(s) property(ies), and the keywords is
& by
new keywords.
interface Bar {
foo: 'bar';
}
interface Baz {
foo: 'baz';
}
const obj!: Bar | Baz;
if(obj is Bar by 'foo') {
// obj is Bar
}
interface Bar {
foo: 'bar';
}
interface Baz {
foo: 'baz';
}
const obj!: Bar | Baz;
if(obj.foo === 'bar') {
// obj is Bar
}
Preprocessor directives are normal language instruction (TS or JS) executed at build time, and marked by a leading #
. Each non-preprocessor instruction ran by the preprocessor logic is appended to the output, with their output replaced.
# const FOO = true;
# if(FOO){
echo 'foo';
# } else {
echo 'bar';
# }
Output:
echo 'foo';