Re:Python’s “type hints” are a bit of a disappointment to me
by ZephyrBlu on Thursday April 21, 2022 @09:29PM
(#31117244)
Like the author said, the weird thing is that it goes both ways. I'm pretty sure if you try to return `any` from a function with an explicit return type in TypeScript you'll get pinged for it.
Re:Python’s “type hints” are a bit of a disappointment to me
by derekbaker783 on Thursday April 21, 2022 @09:46PM
(#31117339)
Not with any TSC settings I've ever used.
Re:Python’s “type hints” are a bit of a disappointment to me
by MBCook on Thursday April 21, 2022 @10:32PM
(#31117595)
noImplicitAny is a very common config option that helps catch a ton of bugs. I wouldn’t use TS without it.
Re:Python’s “type hints” are a bit of a disappointment to me
by mikewhy on Thursday April 21, 2022 @11:10PM
(#31117786)
noImplicitAny is different than what's being discussed (I think). Returning something typed as `any` in a function that has a different return type is totally fine: it's not implicit (you've cast it to any), and it passes (you're saying the type is literally anything after all).
There are lint rules to avoid typing as `any`.
Re:Python’s “type hints” are a bit of a disappointment to me
by DangitBobby on Friday April 22, 2022 @02:31AM
(#31118861)
There are "no explicit any" linting rules as well, which are a must.
The Any type is to allow incremental typing. You start out with dynamic code, and progressively 'typify' it by adding more and more annotations, with Any working as a stopgap where for the moment no valid type exists, until you finally have a fully typed program. Inserting Anys because you're lazy is like casting things to Object in Java because you're lazy, abusing it like that is just incredibly sloppy and bad code.
If someone is really struggling with this, simply use a linting rule to ban Any in 'mature' code.