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

Specify Option.of return type as NonNullable #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants