Типизация в JS
Обзор + пересказ dev2dev
Валерий Кузьмин, Kontur.Recognition, 2017
Зачем?
- Меньше ошибок?
- Проще писать?
JSDoc
(ddserver-api)
/***
* Gets mapping of services to hosts,
* which is useful for controlling or pushing.
* @param {Boolean} extendedHostProperties
* add more info to the hosts property. Added to keep backward compatibility
* @returns {Promise<Object>} a promise which resolves with an object like
* {'KrecServiceHost': ['vm-kr01','vm-kr02']}
*/
Typescript
(Krec.Isomorphic.ts)
export class ValidationMessage extends NObject
{
Code: ValidationErrorCode = null;
MessageParams: any[] = null;
...
IsWarning: boolean = false;
FnsTypeId: string | null | undefined;
}
React.PropTypes
(ClaimNew)
static propTypes = {
onChange: React.PropTypes.func.isRequired,
value: React.PropTypes.string,
borderless: React.PropTypes.bool,
};
Flow
(retail-ui)
type Props = InputProps & {
renderItem: any,
source: any,
};
type State = {
items: ?Array<any>,
selected: number,
};
Варианты
Фича | TypeScript | Flow | PropTypes |
---|---|---|---|
Документация (JSDoc) |
|
||
Рантайм |
|||
IntelliSense (IDE + infer) |
|||
Библиотеки | |||
Eslint | |||
Внедрение | hard | easy | easy |
Сборка |
+
+
-
+
-
+
+
-
+
-
-
+
+
+
+
-
+
+
-
+
-
+
-
js-types-at-krec
By Valeriy Kuzmin
js-types-at-krec
- 633