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

Proposal - Allow 'this' to be used as type #1560

Closed
NN--- opened this issue Dec 25, 2014 · 2 comments
Closed

Proposal - Allow 'this' to be used as type #1560

NN--- opened this issue Dec 25, 2014 · 2 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@NN---
Copy link

NN--- commented Dec 25, 2014

When 'this' is used as type it is replaced with the following interface or class.

class A {
 f(a : this) {} // <=> f(a : A)
 g(x : any) { 
   if (x instanceof this) { } // <=> x instanceof A
}

interface B {
  x : this; // <=> x : B
}
@DanielRosenwasser
Copy link
Member

This is actually a duplicate of #285 (and #1435).

For the record, this-type as an input type is not type safe, as I'll elaborate on in that issue.

@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript Duplicate An existing issue was already created labels Dec 26, 2014
@NN---
Copy link
Author

NN--- commented Dec 26, 2014

Why not type safe?
If this always resolves to the static type of the class it is purely type safe.

I understand the other proposals is to dynamically bind this to the real type beneath, I don't propose it.
Maybe 'typeof this' makes it more clear.

@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
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants