You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simply unwrapping the observable won't work because the observable is a function. According to typescript, functions are nondeterministic, meaning that we can't expect the same return value.
This is a problem because we can't know what condition is passed to the if/ifnot bindings. In the below example, we expect name to be ko.Observable<string> since we checked if the value is not null.
The below example unfortunately does not work since foo will only recieve an overload. So the type will become (): string | undefined & (): string. The return value from this type is string | undefined. In conclusion, asserting the observable will not work.
A solution to this would be to assert all instances of the observable in the descendants of the binding. The downside is that this would probably require a lot of work and slow down the transpiler even more.
Activity
tscpp commentedon Jun 14, 2024
Simply unwrapping the observable won't work because the observable is a function. According to typescript, functions are nondeterministic, meaning that we can't expect the same return value.
The if/ifnot bindings should return a new child context where it extracts all the truthy values from the observable.
tscpp commentedon Jun 14, 2024
This is a problem because we can't know what condition is passed to the if/ifnot bindings. In the below example, we expect name to be
ko.Observable<string>since we checked if the value is not null.The below example unfortunately does not work since foo will only recieve an overload. So the type will become
(): string | undefined&(): string. The return value from this type isstring | undefined. In conclusion, asserting the observable will not work.A solution to this would be to assert all instances of the observable in the descendants of the binding. The downside is that this would probably require a lot of work and slow down the transpiler even more.
Issue is open to suggestions!
[-]if/ifnot bindings does not unwrap observables[/-][+]Narrow types of observables in conditions[/+]