2019-08-10 19:50:14 +02:00
|
|
|
// @strictNullChecks:true
|
|
|
|
|
2019-08-18 18:48:05 +02:00
|
|
|
function onlyErrorsWhenTestingNonNullableFunctionType(required: () => boolean, optional?: () => boolean) {
|
|
|
|
if (required) { // error
|
|
|
|
}
|
2019-08-10 19:50:14 +02:00
|
|
|
|
2019-08-18 18:48:05 +02:00
|
|
|
if (optional) { // ok
|
|
|
|
}
|
2019-08-10 19:50:14 +02:00
|
|
|
|
2019-08-18 18:48:05 +02:00
|
|
|
if (!!required) { // ok
|
2019-08-10 19:50:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (required()) { // ok
|
|
|
|
}
|
2019-08-18 18:48:05 +02:00
|
|
|
}
|
2019-08-10 19:50:14 +02:00
|
|
|
|
2019-08-18 18:48:05 +02:00
|
|
|
function onlyErrorsWhenUnusedInBody() {
|
|
|
|
function test() { return Math.random() > 0.5; }
|
|
|
|
|
|
|
|
if (test) { // error
|
|
|
|
console.log('test');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test) { // ok
|
|
|
|
console.log(test);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test) { // ok
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test) { // ok
|
|
|
|
[() => null].forEach(() => {
|
|
|
|
test();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test) { // error
|
|
|
|
[() => null].forEach(test => {
|
|
|
|
test();
|
|
|
|
});
|
2019-08-10 19:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 18:48:05 +02:00
|
|
|
function checksPropertyAccess() {
|
2019-08-10 19:50:14 +02:00
|
|
|
const x = {
|
|
|
|
foo: {
|
2019-08-18 18:48:05 +02:00
|
|
|
bar() { return true; }
|
2019-08-10 19:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x.foo.bar) { // error
|
|
|
|
}
|
|
|
|
|
2019-08-18 18:48:05 +02:00
|
|
|
if (x.foo.bar) { // ok
|
|
|
|
x.foo.bar;
|
2019-08-10 19:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Foo {
|
|
|
|
maybeIsUser?: () => boolean;
|
|
|
|
|
|
|
|
isUser() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
test() {
|
|
|
|
if (this.isUser) { // error
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.maybeIsUser) { // ok
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|