Skip to content

Type inference in Array<T>.filter()Β #46987

Closed
@LouisBoucquet

Description

@LouisBoucquet

Bug Report

πŸ”Ž Search Terms

Type inferance

πŸ•— Version & Regression Information

This bug occurs in version 4.5.2;

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function tIsOfTypeP(t: T): t is P {
	// Logic
}

const array: T[] = [...];

// newArray is still of type T[]
const newArray = array
	.filter(t => tIsOfTypeP(t));

πŸ™ Actual behavior

The variable newArray is of type Array<T>.

πŸ™‚ Expected behavior

The variable newArray is of type Array<P>. You know that only elements will remain of type P.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions