Ranvier-TS / core-ts

Core engine code for Ranvier (in TypeScript!!!)
https://ranviermud.com/
MIT License
9 stars 4 forks source link

Using never to return from Area::getRoomById(...) #12

Closed rogersm closed 3 years ago

rogersm commented 3 years ago

Folks,

why are we doing typing the return from Area::getRoomById with never?

getRoomById(id: string): Room | never {
    const room = this.rooms.get(id);
    if (!room) {
        throw new Error(`Area did not find Room with id: [${id}]`);
    }
    return room;
}

Never should be used for:

And in this case we return (room) or we may (but not always) thrown an Error.

Shouldn't this be:

getRoomById(id:string): Room { ... }

seanohue commented 3 years ago

I've seen never used to annotate the fact that the method returns an error but if that's an antipattern we can remove it

rogersm commented 3 years ago

That would be my recommendation.

Typescript Deep Dive Book describes the use of never in detail.

seanohue commented 3 years ago

Makes sense to me -- let's ditch it, then.

On Mon, May 17, 2021 at 2:57 PM Roger Sen @.***> wrote:

That would be my recommendation.

Typescript Deep Dive Book describes the use of never in detail. https://basarat.gitbook.io/typescript/type-system/never

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Ranvier-TS/core-ts/issues/12#issuecomment-842555637, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6GX6IHE3Y4KQTGOW2PEXTTOFRKBANCNFSM447B7QFA .