Как настроить линтер Typescript'a

Я только начинаю изучение TypeScript'a.

Код в файле main.ts:

// ...
type response = string | Buffer;
let data: response;
if (options && options.bin) data = Buffer.from([]);
else data = '';
// ... появляется переменная chunk: Buffer
if (options && options.bin) Buffer.concat([data, chunk]);
else data += chunk.toString();

Линтер подчеркивает data в пердпоследней строке. Пишет:

Type 'response' is not assignable to type 'Uint8Array'.

Type 'string' is not assignable to type 'Uint8Array'.ts(2322)

Ну, ладно, думаю, хочешь Uint8Array, давай сделаю Uint8Array. Меняю

Buffer.concat([data, chunk])

на

Buffer.concat([ new Uint8Array.from(data), chunk ])

Получил:

No overload matches this call.

Overload 1 of 3, '(arrayLike: Iterable, mapfn?: (v: number, k: number) => number, > thisArg?: any): Uint8Array', gave the following error.

Argument of type 'response' is not assignable to parameter of type 'Iterable'.

 Type 'string' is not assignable to type 'Iterable<number>'.

Overload 2 of 3, '(arrayLike: ArrayLike): Uint8Array', gave the following error.

Argument of type 'response' is not assignable to parameter of type 'ArrayLike'.

 Type 'string' is not assignable to type 'ArrayLike<number>'.ts(2769)

Конечно, то, что получается командой tsc main.ts - работает. Но красное подчеркивание меня откровенно говоря напрягает. Как мне дать понять TypeScript'у, что всё нормально?


Ответы (0 шт):