-
Notifications
You must be signed in to change notification settings - Fork 55
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
Build should error with config that has strictNullChecks: false
#152
Comments
@nygrenh hm... so there's no specific test cast for union type with |
export function isExample(obj: any, _argumentName?: string): obj is Example {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
(obj.name === null ||
typeof obj.name === "string")
)
} |
@nygrenh this is known behaviour. There is a conceivable way that you could generate guards with strictNullChecks disabled, it would basically mean allowing any field or object to be We could forcibly override this option before ts-auto-guard runs. However that would give incorrect results too. For example: import { isMyInterface } from "./MyInterface.guard.ts"
// without null checks
interface MyInterface {
value: int;
}
let valueInt: MyInterface = { value: 5 }; // valid
let valueUndefined: MyInterface = { value: undefined }; // valid
let valueNull: MyInterface = { value: null }; // valid
isMyInterface(valueInt); // true
isMyInterface(valueUndefined); // incorrectly returns false
isMyInterface(valueNull); // incorrectly returns false But if we go the other way and permit any value to be undefined or null it's a lot of noise and the end validators are mostly useless. So it's not really clear how to handle this setting. Generally speaking the goal of this project is to create type checks for people who want strict types, so the intersection with people working with I think the solution is to warn or error when the program runs. |
strictNullChecks: false
Yeah, I actually had I agree that a warning / error would be a good solution to this. Thanks for your help! |
Marking this issue as "help wanted". Further discussion notwithstanding, the accepted solution will error the build if |
strictNullChecks: false
strictNullChecks: false
Further thoughts... The ideal behaviour here would be for ts-morph to handle this naturally by including |
Given the following interface:
If I generate a type guard for this, it creates the following function:
Now if call the type guard like this:
The output is false, but I'd expect this to output true.
The text was updated successfully, but these errors were encountered: