TypeScript 3.3.1
This imho should not be allowed:
const foo = { foo: false } as { foo: boolean, bar: boolean };
As it bypasses the type checker from doing its job. I now have basically introduced a type with undefined as foo.bar even though it should be boolean | undefined.
If someone wants this type by all means, it is still possible by using any.
const foo = { foo: false } as any as { foo: boolean, bar: boolean };
That way at least one can find hacks easily.
I would like to see a warning for this, possibly via some kind of new strict rule ideally.
I actually use as or <> a lot in my code to get IntelliSense for an object literal I am writing and ensuring the values I give it are correct, but now I am not so sure anymore.
TypeScript 3.3.1
This imho should not be allowed:
As it bypasses the type checker from doing its job. I now have basically introduced a type with
undefinedasfoo.bareven though it should beboolean | undefined.If someone wants this type by all means, it is still possible by using
any.That way at least one can find hacks easily.
I would like to see a warning for this, possibly via some kind of new strict rule ideally.
I actually use
asor<>a lot in my code to get IntelliSense for an object literal I am writing and ensuring the values I give it are correct, but now I am not so sure anymore.