Skip to content
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

property: PropertyValueSet.fromStringOrError cannot return undefined #15

Open
jonaskello opened this issue Nov 25, 2019 · 1 comment
Open

Comments

@jonaskello
Copy link
Member

jonaskello commented Nov 25, 2019

I guess the reason for having PropertyValueSet.fromStringOrError() is that we can parse a string wihtout causing exceptions. However the typing now only allows the return value of PropertyValueSet which means that the onError function must return PropertyValueSet and thus is is not possible to know from the result if the string did parse or not since the return value is always a valid PropertyValueSet even when the parsing fails.

For example this code does not compile:

const parsed = PropertyValueSet.fromStringOrError(() => undefined, s, Units);
@jonaskello
Copy link
Member Author

It seems PropertyFilter.fromString() is typed differently than PropertyValueSet.fromString(). It can return undefined:

PropertyFIlter

function fromString(filter: string, units: Unit.UnitMap): PropertyFilter | undefined;
function fromStringOrEmpty(filterString: string, units: Unit.UnitMap): PropertyFilter;

PropertyValueSet

export declare function fromString(encodedValueSet: string, units: Unit.UnitMap): PropertyValueSet;
export declare function fromStringOrError(onError: (encodedValueSet: string) => PropertyValueSet, encodedValueSet: string, units: Unit.UnitMap): PropertyValueSet;

I think the API should be as similar as possible between these two.

@jonaskello jonaskello changed the title PropertyValueSet.fromStringOrError cannot return undefined property: PropertyValueSet.fromStringOrError cannot return undefined Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant