News for hackers. Stuff that matters.
Re:TIL: `satisfies` is my favorite TypeScript keyword by triyambakam on Sunday November 23, 2025 @02:33AM (#46021544)
That scenario is usually either misuse of escape hatches (especially at API boundaries) or a misunderstanding of what Typescript actually guarantees.
Re:TIL: `satisfies` is my favorite TypeScript keyword by debugnik on Sunday November 23, 2025 @02:56AM (#46021640)
Not really, I provided these examples a couple weeks ago on another HN thread. TypeScript is simply unsound.

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAllApg...

https://www.typescriptlang.org/play/?#code/DYUwLgBAHgXBB2BXA...

Re:TIL: `satisfies` is my favorite TypeScript keyword by jstanley on Sunday November 23, 2025 @03:38AM (#46021815)
Perfect examples of the kind of thing I'm talking about, thank you.
Re:TIL: `satisfies` is my favorite TypeScript keyword by LordN00b on Sunday November 23, 2025 @04:37AM (#46022060)
In the first example you deliberately create an ambiguous type, when you already know that it's not. You told the compiler you know more than it does. The second is a delegate, that will be triggered at any point during runtime. How can the compiler know what x will be?
Re:TIL: `satisfies` is my favorite TypeScript keyword by debugnik on Sunday November 23, 2025 @04:46AM (#46022098)
First example: you're confusing the annotation for a cast, but it isn't; it won't work the other way around. What you're seeing there is array covariance, an unsound (i.e. broken) subtyping rule for mutable arrays. C# has it too but they've got the decency to check it at runtime.

Second example: that's the point. If the compiler can't prove that x will be initalised before the call it should reject the code until you make it x: number|undefined, to force the closure to handle the undefined case.

Re:TIL: `satisfies` is my favorite TypeScript keyword by bspammer on Sunday November 23, 2025 @04:44AM (#46022087)
For the first one, the compiler should not allow the mutable list to be assigned to a more broadly typed mutable list. This is a compile error in kotlin, for example

    val items: MutableList<Int> = mutableListOf(3)
    val brokenItems: MutableList<Any> = items
Re:TIL: `satisfies` is my favorite TypeScript keyword by swiftcoder on Sunday November 23, 2025 @05:49AM (#46022416)
> The second is a delegate, that will be triggered at any point during runtime. How can the compiler know what x will be?

x is clearly defined to be a number. The compiler should produce an error if the delegate captures x before it has a value assigned.

Re:TIL: `satisfies` is my favorite TypeScript keyword by jstanley on Sunday November 23, 2025 @04:41AM (#46022073)
If it only works when you write the types correctly with no mistakes, what's the point? I thought the point of all this strong typing stuff was to detect mistakes.
Re:TIL: `satisfies` is my favorite TypeScript keyword by macguillicuddy on Sunday November 23, 2025 @05:40AM (#46022356)
Because adding types adds constraints across the codebase that detect a broader set of mistakes. It's like saying what's the point of putting seatbelts into a car if they only work when you're wearing them - yes you can use them wrong (perhaps even unknowingly), but the overall benefit is much greater. On balance I find that TypeScript gives me huge benefit.
Re:TIL: `satisfies` is my favorite TypeScript keyword by sandblast on Sunday November 23, 2025 @07:58AM (#46023216)
Aren't these bugs that could be "simply" reported and fixed? Or maybe those would get a label "not a bug" attached by the TS creators for some reason?
Re:TIL: `satisfies` is my favorite TypeScript keyword by debugnik on Sunday November 23, 2025 @08:24AM (#46023368)
Both are by design. Array covariance is a common design mistake in OOP languages, which the designer of TypeScript had already done for C# but there they at least check it at runtime. And the latter was declared not-a-bug already IIRC.

TypeScript designers insist they're ok with it being unsound even on the strictest settings. Which I'd be ok with if the remaining type errors were detected at runtime, but they also insist they don't want the type system to add any runtime semantics.

Re:TIL: `satisfies` is my favorite TypeScript keyword by sandblast on Sunday November 23, 2025 @09:05AM (#46023654)
"By design", for me, doesn't say that it can't be changed — maybe the design was wrong, after all. Would it be a major hurdle or create some problems if fixed today?