-
Notifications
You must be signed in to change notification settings - Fork 38
Be strictNullChecks
compatibility
#52
Comments
Working on an alternative library with pretty similar functionality and modern TS support: |
@patrickmichalina yeah, we can all build our own library, just kinda defeats the purpose :) Hmm, looking at your code, I think it also only handles |
If people kept up on their repos, it wouldn’t be necessary :) I’ll check out your comments and adjust accordingly. Thanks. |
@patrickmichalina @JohannesHome Sorry for bothering you with same repeated idea. I recently built https://github.com/Ailrun/typed-f and I believe these packages satisfy all usage with |
@Ailrun looks good, but it it isn't type safe. Simple example is already the signature for This let's me do stuff like this: const test: string | undefined = undefined;
const from = Maybe.from(test);
const result: string = from.valueOr(1); without a compile error. Also the docs could be more comprehensive. And yeah I know I can force the type with |
@JohannesHome Oh, thank you for feedback. Maybe.from<T>(value?: null): Nothing<T>; Following code will give you wrong type. const test: string | undefined = undefined;
const from = Maybe.from(test); // This will give you Nothing<{}> Though it will give you an error for following statement. const result: string = from.valueOr(1); // Complain about that `{}` cannot be assigned to `string`. |
@JohannesHome Following code will give you better explanation. function x(test: string | undefined) {
const from = Maybe.from(test);
return from.valueOr(1); // Give you an error!
} Your code works since TS think your const test: string | undefined = undefined;
const x: number | undefined = test; |
@Ailrun this is a bit out of scope but your library could infer the type based on the actual value like so |
@JohannesHome |
@JohannesHome These are all because TS knows what the value of |
|
Currently, when using this library with the flag enabled we have the following issue:
As you can see
result
keeps the typenull
, since the current typings reflect this. It would be nice if the type formap
could reflect the removal of null. Example:I saw that in #31 this point has been mentioned and fixed for
Maybe.maybe
but not in general.Currently there is not a single
optional
ormaybe
typescript library out there that is fullystrictNullChecks
compatible.My question, is this planned?
The text was updated successfully, but these errors were encountered: