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

Does typeguard work with expressions, i.e. ev.target? #2184

Closed
TimKelly2 opened this issue Mar 2, 2015 · 3 comments
Closed

Does typeguard work with expressions, i.e. ev.target? #2184

TimKelly2 opened this issue Mar 2, 2015 · 3 comments
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript

Comments

@TimKelly2
Copy link

A cast appears to work with the expression, ev.target.

         if(ev.target instanceof Node) {
             var n : Node = <Node>ev.target;
             n.appendChild(document.getElementById(data));
         }

A typeguard appears to work with the simple variable, t.

         var t = ev.target;
         if(t instanceof Node) {
             var n : Node = t;
             n.appendChild(document.getElementById(data));
         }

A typeguard appears to fail with an expression, ev.target or (ev.target).

         if(ev.target instanceof Node) {
             ev.target.appendChild(document.getElementById(data));
         }
@danquirk
Copy link
Member

danquirk commented Mar 2, 2015

This is by design currently (the spec section on type guards only mentions narrowing variables and properties, not dotted names). We can consider augmenting the narrowing functionality but there are concerns about side effecting function calls.

@danquirk danquirk added Suggestion An idea for TypeScript Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Mar 2, 2015
@TimKelly2 TimKelly2 changed the title Does typeguard work with expresssions, i.e. ev.target? Does typeguard work with expressions, i.e. ev.target? Mar 2, 2015
@zspitz
Copy link
Contributor

zspitz commented Apr 15, 2015

+1

@mhegazy
Copy link
Contributor

mhegazy commented Feb 22, 2016

closing in favor of #3812

@mhegazy mhegazy closed this as completed Feb 22, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants