Skip to content

Guarded function declarations #9253

Closed
Closed
@tinganho

Description

@tinganho

I sometimes reference outer scope variables and class members in my function/method declarations. The problem is that those references are nullables. I want a way to ensure that a function is called on a call site where those references are not null.

let corns: string | null;
function makePopCorn(): string 
    requires corns !== null
{
   return 'pop';
}
if (corns) {
   makePopCorn();
}
makePopCorn(); // error corns can be null

Related #198. But not duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions