только рест апи. Надо затипизировать то, что может вернуть бэкенд.
It's to allow patterns such as n = n + 1.
Разработчики объясняют это тем, что они используют TypeScript, и он находится в папке src, поэтому вот так все собирается
Не нравится идея копировать dist и все вложенные папки
Не рекомендуют запускать npm install заново на сервере, так как по их мнению могут подтянуться совсем другие версии
package-lock.json
пытались использовать, но потом отказались - в версиях NPM 5.0-5.2 он работал отвратительно, сейчас уже может получше, не знаю. const foo: IFoo = {
bar: [
{a: "white", b: 10},
{a: "black", b: 20}
]
}
interface NodeRequireFunction {
(id: string): any;
}
interface NodeRequire extends NodeRequireFunction {
resolve(id: string): string;
cache: any;
extensions: any;
main: NodeModule | undefined;
}
declare var require: NodeRequire;
This is a bit subtle, but number[] | string[] !=== (number | string)[]. The first one has an assert on homogeneity, while the second does not. just as in the example noted above by @kaotik4266, [0, "1", 2] is not of type number[] | string[].
There is not a meaningful way to describe the general case for merging unmatching signatures; while filter might be arguably safe, push is not. So merging the signatures of (number[]|string[]).push(...) th same proposed for filter would result in push(a: number | string); which means that we are treating the original type as (number | string)[], which is not type safe.
So the general case, is there is no common signatures between the two types, and thus the resulting union type does have a filter property but it does not have a signature, and hence the error message Cannot invoke an expression whose type lacks a call signature.
function isNumbers(arr: number[] | string[]): arr is number[] {
return arr.length === 0 || // В случае нулевой длины тип элемента массива нам не важен, примем его за number
typeof arr[0] === "number"; // Либо проверим фактический тип первого элемента. Этого должно быть
// достаточно, т.к. в типе 'arr' декларируется однородность массивов
}
function getHandler(handlers: number[] | string[]): number[] | string[] {
if (isNumbers(handlers)) {
return handlers.map(handler => handler);
} else {
return handlers.map(handler => handler);
}
}
Можно учить typescript без нативного js?
если нет обоснованной причины писать на ts - не пиши
TS похож на конструктор сайтов. Вроде сайт на TS, но работает на JS. Так в этом конструкторе придется еще и свою локигу вставлять.
И какие плюсы ts перед js?
Теперь осталось понять, как включить автоматическое генерирование заголовков для своих модулей и как их публиковать.
--declaration
.Отдельно о публикации - над npm я использую sinopia, хочется работать с похожей утилитой и для ts заголовков.
Что кто может сказать про TypeScript?
Goals
...
4. Emit clean, idiomatic, recognizable JavaScript code.
...
Non-goals
2. Aggressively optimize the runtime performance of programs. Instead, emit idiomatic JavaScript code that plays well with the performance characteristics of runtime platforms.
class Foo {
constructor(a, b) {
this.a = a;
this.b = b;
}
bar() {
return this.a + this.b;
}
}
class Foo {
private a: number;
private b: number;
constructor(a, b) {
this.a = a;
this.b = b;
}
bar() {
return this.a + this.b;
}
}
_createClass
и _classCallCheck
, которые определены достаточно нетривиально. Зачем он это делает? Затем, что Бабель генерирует код, "безопасный" в райнтайме. Он не рассчитывает на то, что какие-либо проверки будут выполняться при компиляции. Например, в хелпере _classCallCheck проверяется, что конструктор не был вызван, как обычная функция.