-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add compiler option to require explicit casts from any to other types #22716
Comments
That library definition is arguably poor; If |
@krryan Thank you for the suggestion! In practice, |
True, |
TSLint's declare let foo: any;
declare let bar: string;
foo.bar; // lint error
foo(); // lint error
bar = foo; // lint error But it doesn't detect declare let foo: any[];
declare let bar: string[];
bar = foo; // this is still possible |
This needs some very careful spec'ing to be actionable. The problem is that There are also places where there's an assignability relationship to class Base {
foo(): any { return null; }
}
class Derived extends Base {
foo() { return 0; }
} This is in principle an error because a It's a trivial change to just "make |
Thanks Ryan! That’s a very informative comment. Looks like the current situation would be best solved with a linter, and in the long term by the |
TypeScript Version: [email protected]
Search Terms: explicit any conversion
Code
Expected behavior: I can use a compiler option to require an explicit cast from
any
tostring
, and the code above would give an error with that option enabled. Functionx
in the example usually comes from a library definition file like: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/9f4c75126167d0d8af759f58405d53d983e94ad0/types/yargs/index.d.ts#L226Actual behavior: There is no such option.
Playground Link: http://www.typescriptlang.org/play/index.html#src=function%20x()%3A%20any%20%7B%0D%0A%20%20%20%20return%2042%0D%0A%7D%0D%0A%0D%0Aconst%20y%3A%20string%20%3D%20x()
Related Issues: #22464 (comment)
The text was updated successfully, but these errors were encountered: