After using TypeScript there's some features that I'm terrified of that seem counter intuitive. All the following examples produce NO errors and are with every single strict TS option enabled.
-
-
I found out recently that TS types are nullable by default unless you enable the `strictNullChecks` option. e.g. this is a completely valid TS program by default, but will crash immediately. Seems... bad.pic.twitter.com/v3nMGKubwH
-
Yeah it's really weird. I think that one is forgiveable because at least it's an option and the `strict` option is what seems to be the community recommended default tsconfig.
- 1 more reply
New conversation -
-
-
const arr: Array<number> = []; const item = arr[0]; // number, not number | undefinedhttps://github.com/microsoft/TypeScript/issues/13778 …
-
Same goes for Flow too. I wish they had bounds refinements so for most cases it can be just `T` rather than `T | undefined`. I've found myself having to do completely unnecessary checks constantly with my TS code when doing `while (arr.length > 0) { arr.shift(); }`
- 2 more replies
New conversation -
-
-
as & is are my least favorite parts about reading TS code
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
This is probably legacy since 'unknown' is semi-new. Without too much thought, unknown does seem more correct there. Strictly speaking this is separate from the language though, it's just the type definition for isArray. You can probably redefine it yourself if you'd like.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Probably worth filing a bug for this one, they tend to be highly responsive to bugs (if it is indeed a bug)
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
The number one priority in TypeScript, as I understand it, is not to break working JavaScript. Things like type assertions are for when TS doesn’t necessarily detect a type exactly as it should. It’s essentially a manual override.
-
The language isn’t designed to be 100% foolproof. They went with the idea that letting some of the guilty go free was better than jailing some of the innocent. Everything has tradeoffs but if you’re used to writing JS then this actually makes the transition easier.
End of conversation
New conversation -
-
-
Type guards (as used in `isArray`'s declaration, `isArray(arg: any): arg is Array<any>`) predate `unknown`. Your point makes sense but, as always, it's about trade-offs: switching to `unknown` now is a breaking change and I think the
@typescript team simply didn't want that.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 