Skip to content

Type guard not working in returned function #12616

Closed
@andraaspar

Description

@andraaspar

TypeScript Version: 2.2.0-dev.20161202

Code

function getGetter() {
	let data = {}
	data['bar'] = 1
	
	if (hasBar(data)) {
		return () => data.bar // Property 'bar' does not exist on type '{}'.
	}
}

function hasBar(thing): thing is {bar: number} {
	return typeof thing.bar == 'number'
}

Expected behavior:
Compile successfully.

Actual behavior:

index.ts(6,21): error TS2339: Property 'bar' does not exist on type '{}'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions