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

Appearance settings

Narrowed is fail when use as T #36613

Copy link
Copy link
@bluelovers

Description

@bluelovers
Issue body actions

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms:

Code

export type IGunEpubNode = {
	timestamp: number,
	exists: false,
} | {
	timestamp: number,
	exists: true,

	filename: string,
	base64: string,
}

this will fail

 Error:(12, 10) TS2339: Property 'base64' does not exist on type 'IGunEpubNode'.
Error:(12, 18) TS2339: Property 'filename' does not exist on type 'IGunEpubNode'.
export function checkGunData<T extends IGunEpubNode>(data: T)
{
	if (data && data.timestamp)
	{
		if (data.exists)
		{
			let { base64, filename, exists, timestamp } = data;

			return true;
		}
	}

	return null;
}

image

this will work

checkGunData(data: IGunEpubNode)

image

Expected behavior:

both code should narrowed

checkGunData<T extends IGunEpubNode>(data: T)
checkGunData(data: IGunEpubNode)

Actual behavior:

this failed

checkGunData<T extends IGunEpubNode>(data: T)

Playground Link: http://www.typescriptlang.org/play/#code/KYDwDg9gTgLgBDAnmYcCSBxArgOwKJhYBGAchACaoC8cA3gLABQAkDAJYC2wAzjAIYcwALjg4sHIsCgAaJs1Bte3EQDM+AG27BZjAL5wAPnTnsuvAcNHjJMuQqUiYULNqZyVbdcBwDgI3lBsOADmOsxEfFoAbAAs-k5BoUy6boygkLBwKrgAxuwQOHA5ABbAOQDW2DgAInz8ADwAKnCgMN7k3OhVBMRklAB8ABTkdXwijQCUTAwsbCpww6NwAGTLcCP8AHSmPPyCUywzzMxzCxt8m-Yw3AfHR8de8LRwEdEx0lme3r4fV9wfO3Mgjg+ho5wA3KljswoMAYFgoIUnC5ISxmCkWBi5LD4YirOp1KjdEA

Related Issues:

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.