class Result<T>{
public readonly result;
constructor(result: T){
this.result = result;
}
}
class NumberResult extends Result<number>{
constructor(result: number){
super(result);
}
public ResultPlusOne(){
return this.result + 1;
}
}
Result<T>
- это открытый дженерик, то есть в будущем на месте T должен быть указан другой\типы или типы для того чтобы создавать экземпляры класса.let result = new Result<number>(42)
class Result{
public readonly result;
constructor(result: number){
this.result = result;
}
}
class NumberResult extends Result<number>
class Base<T> {
protected val: T;
}
class A extends Base<string> {
methodA(): string {
return this.val; // Ok, так как здесь val имеет тип string
}
}
class B extends Base<number> {
methodB(): number {
return this.val; // тоже ok, так как здесь val имеет тип number
}
}
fs.writeFile(file, data[, options], callback)#
History:
- file
<string> | <Buffer> | <URL> | <integer>
filename or file descriptor- data
<string> | <Buffer> | <TypedArray> | <DataView> | <Object>
- options
<Object> | <string>
- encoding
<string> | <null>
Default: 'utf8'- mode
<integer>
Default: 0o666- flag
<string>
See support of file system flags. Default: 'w'.- signal
<AbortSignal>
allows aborting an in-progress writeFile- callback
<Function>
- err
<Error> | <AggregateError>
When file is a filename, asynchronously writes data to the file, replacing the file if it already exists. data can be a string or a buffer.
When file is a file descriptor, the behavior is similar to calling fs.write() directly (which is recommended). See the notes below on using a file descriptor.
The encoding option is ignored if data is a buffer.
If data is a plain object, it must have an own (not inherited) toString function property.
...
fs.write
). После этого нужные пункты оглавления подсветятся желтым и вы легко найдете нужный. document.querySelector('.case-print')
type CreatureBasis = {
People: {
child: {
age: number;
school: string;
};
adult: {
age: number;
height: number;
weight: number;
};
};
Animal: {
fish: {
waterBody: string;
};
cat: {
catchMouses: boolean;
};
};
};
type Creature = {
[K0 in keyof CreatureBasis]: {
[K1 in keyof CreatureBasis[K0]]: {
type: K0;
subtype: K1;
params: CreatureBasis[K0][K1];
};
}[keyof CreatureBasis[K0]];
}[keyof CreatureBasis];
const obj = {
val: 1,
valueOf() {
return this.val ^= 1;
},
};
// или
const obj = {
val: '1',
toString() {
return this.val = '1'.slice(this.val.length);
},
};
// или
const obj = {
val: true,
[Symbol.toPrimitive]() {
return this.val = !this.val;
},
};
console.log(obj == false, obj == true); // true true
console.log(...Array.from({ length: 5 }, () => +obj)); // 0 1 0 1 0
Array.from(str, n => n < 5 ? 0 : 1).join('')
// или
[...str].reduce((acc, n) => acc + +(n >= 5), '')
// или
''.concat(...str.split('').map(n => Math.floor(n / 5)))
// или
[].map.call(str, n => -~-~-~n >> 3).join``
// или
str.replace(/./g, m => Number('56789'.includes(m)))
// или
str.replace(/[1-4]/g, 0).replace(/[5-9]/g, 1)
будет ли работодатель рассматривать на позицию миддл бек бывшего миддла фронтендщика ?конечно будет, если потяните и сможете это доказать.
let b = [1, 2, 3, 0, 4, 5, 6];
const sum = b.slice(0, b.findIndex(e => e === 0)).reduce((total, amount) => total + amount);
console.log(sum)