Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Specify Option.of return type as NonNullable #134

Closed
wants to merge 1 commit into from

Conversation

OliverJAsh
Copy link
Contributor

Re. microsoft/TypeScript#19469 (comment)

In TS, we have this issue:

declare class Maybe<A> {
    static of<A>(value: A | undefined): Maybe<A>;
    map<B>(f: (a: A) => B): Maybe<B>;
}

{
    type User = { name: string };
    const logUser = (_user: User) => {};

    type State = {
        user: User | undefined;
    };

    const fn = function<Own extends {}>(p: Readonly<Own & State>) {
        const { user } = p;

        Maybe.of(user).map(
            user =>
                // Unexpected error: Object is possibly 'undefined'.
                user.name,
        );
    };
}

Annotating Option.of return type as NonNullable, as recommended in the TS issue, fixes this.

Re. microsoft/TypeScript#19469 (comment)

In TS, we have this issue:

``` ts
declare class Maybe<A> {
    static of<A>(value: A | undefined): Maybe<A>;
    map<B>(f: (a: A) => B): Maybe<B>;
}

{
    type User = { name: string };
    const logUser = (_user: User) => {};

    type State = {
        user: User | undefined;
    };

    const fn = function<Own extends {}>(p: Readonly<Own & State>) {
        const { user } = p;

        Maybe.of(user).map(
            user =>
                // Unexpected error: Object is possibly 'undefined'.
                user.name,
        );
    };
}
```

Annotating `Option.of` return type as `NonNullable`, as recommended in the TS issue, fixes this.
@OliverJAsh
Copy link
Contributor Author

@alexandru Any thoughts on this?

@OliverJAsh
Copy link
Contributor Author

Hi @alexandru, is this library still being maintained?

@alexandru
Copy link
Member

@OliverJAsh unfortunately due to my other commitments and the fact that I'm no longer involved in TypeScript driven projects, for the last couple of months the library has been unmaintained.

It's not by intention and I'm pretty sure I'll get involved in other TypeScript projects in the future.

I'm looking for options, to share the maintenance burden with other people.

@alexandru
Copy link
Member

@OliverJAsh fyi I'm updating the dependencies and will merge this too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants