Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Type guards in Array.prototype.filter #7657

Closed
Labels
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisSuggestionAn idea for TypeScript
@calebegg

Description

@calebegg

TypeScript Version:

nightly (1.9.0-dev.20160323)

Code

letnumbers:number[]=[1,'2',3,'4'].filter(x=>typeofx!=='string');declarefunctionisNumber(arg:any):arg isnumber;letnumbers2:number[]=[1,'2',3,'4'].filter(isNumber);

Playground

Expected behavior:
.filter with a type guard returns an array of the specified type. This would be especially useful with--strictNullChecks, so we could do something likefoo.map(maybeReturnsNull).filter(x => x != null)....

Actual behavior:
.filter returns an array of the same type, and the twolets above are errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp