JoshuaKGoldberg / JoshuaKGoldberg/TypeStat

Strict null checks: allow manual or inferred preferences between assertions or declaration changes

Open
#41 0 comments 0 reactions 0 assignees View on GitHub
area: architecture status: in discussion status: proposal needed
Dominant language
TypeScript
Stars
2.3k
Forks
47
Avg merge
15h 55m
Merged PRs (30d)
21

Description

```typescript
function takesOptional(param: string) {
if (param === undefined) {
return "";
}

return param;
}

takesOptional(undefined);
```

...or the equivalent with a ternary or simpler if or etc.

In this case, we should probably prefer changing the parameter type to `string | undefined`. How can TypeStat know to do this?

How about adding a `"preferences"` section to options that would allow changing the behavior here? It could be one of:
* Infer when possible, defaulting to `!` assertions
* Infer when possible, defaulting to declaration types
* Always use `!` assertions
* Always use declaration types

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.