|
|
|
|
|
by julik
775 days ago
|
|
The worst I had to deal with was converting anything browser-native into data structures that would satisfy the type checker (dealing with native references), and the whole "struct or class instance" dichotomy. Specifically - when there is a lot of DOM-native input (like drag&drop events and their targets and the targets of their targets) that have to be "repackaged" into a TS tree (ending up with properties which would be a JS-version of void*). An example of what I call "ceremony" would be interface BlockIndex {
[key: string]: UploaderBlock;
}
const perServerId = {} as BlockIndex;
uploaderFiles.map((fe) => fe.blocks.map((b) => b.serverId && (perServerId[b.serverId] = b)));
While somewhat useful, this is in internal code which never gets used directly, and there are 4 lines of ceremony for 1 line of actual code. |
|
Something like:
And typescript infers the types correctly. But I still wouldn’t write it as one line, and I’d use lodash instead.