News for hackers. Stuff that matters.
Re:Ask HN: TypeScript experts, is this a type checking issue? by n_e on Sunday September 01, 2019 @07:47AM (#20851773)
any is assignable to anything so what you’re seeing here is the expected behavior.

What I’d recommend is not to use any (and enable the linter rules to disable it) and rather use unknown (which is assignable to nothing) or generics.

On a more general note, typescript is not sound (though it works well in practice) and you’ll always be able to find incorrect code that typechecks, even without using any.

Re:Ask HN: TypeScript experts, is this a type checking issue? by chupa-chups on Sunday September 01, 2019 @08:48AM (#20851988)
Thanks for the reply. I'm writing a ts parser and stumbled over this.

The reason I find it strange is that in this case it appears detectable that the return type will not match (independent of the any type in the parameter).

Is there a reason not to check this I'm not seeing?

By the way, I am quite amazed at the quality (and depth) of the typescript type inference & check model (despite it being "not sound" to quote you).

Re:Ask HN: TypeScript experts, is this a type checking issue? by sbergot on Sunday September 01, 2019 @09:37AM (#20852192)
The reason is that any is an escape mechanism. Typescript will never complain about anything when dealing with this type. Its use case is to perform a step by step migrations from js or to deal with rare corner cases when you can prove yourself that the code is correct.