Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain type guard info #12269

Closed
electricessence opened this issue Nov 15, 2016 · 1 comment
Closed

Retain type guard info #12269

electricessence opened this issue Nov 15, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@electricessence
Copy link

electricessence commented Nov 15, 2016

Is a bit of a low value feature, but TS is getting smarter all the time so why not:

If you can assert that a value is the result of a type guard. Why not keep that information for later?

function report(unknown:Object) {
	const t = typeof unknown;
	console.log(unknown, "is a",t);
	switch(t) // ** 
	{
		case "string":
			let s:string = unknown; // ** should compile without warning.
			// do string operations with s.
			break;

		// More similar cases...
	}
}
@normalser
Copy link

#12184 (comment)

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Nov 15, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants