Skip to content

Divide by zero Typechecking #21955

@ccorcos

Description

@ccorcos

We have type literals for numbers already and a strictNullCheck compiler option -- wouldn't it be awesome if we had a type guard again divide-by-zero errors? I'm building a game that involved a lot of math, computing intersections of lines and such. But what if a line is parallel? It would be cool if the compiler would suggest this as a type error.

function f(): number | 0 {
    return 0
}

const y = 100 / f()

TypeScript Version: 2.7.0-dev.201xxxxx

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions