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
question: performance impact of using this parameter that IS NOT type this
#40704
Comments
@sandersn any ideas? |
In case this helps reduce time someone need to search for relevant stuff: You mentioned to look at the comments on #6739 and a search for the word "performance" brings up this comment which mentions Thanks for the rapid response, really appreciate the work you all do! 🥇 |
It really depends on the context. In that context in the binder, it is looking for In general, I would like to say that a |
To clarify further, that comment is still accurate because a "strict |
excellent, thank you so much for the clarification. :). Have a wonderful day! |
An easy way to think of this is: the
|
I don't know if we should - to me, In other words, |
see Ryan's QA here and the below playground for why declare let returnsVoid: ()=>void
declare let returnsUndefined: ()=> undefined
declare let returnsNumber: ()=> number
// returning void means the return value is un-observed, so any return value is assignable to it.
returnsVoid = returnsUndefined;
returnsVoid = returnsNumber;
// however returning undefined is not forgiving in the same way
returnsUndefined = returnsNumber;
declare let thisVoid: (this: void) => void;
declare let thisUndefined: (this: undefined) => void;
declare let thisNumber: (this: number) => void;
// by the same token, a function that does not observe the `this` parameter is perfectly valid to bind it to anything
thisUndefined = thisVoid
thisNumber = thisVoid
// and using this: undefined does not have the same desired behaviour.
thisNumber = thisUndefined |
Search Terms
this, polymorphic this type, this parameter, performance.
#35451, #6739
Question
I'd like a bit of clarification on this comment about
this
parameter causing drop in performance:Does the presence of a
this
parameter cause drop in performance or using thethis
type? Specifically does doingmethod(this: void)
have any negative performance impact?There was a discussion over at typescript-eslint/typescript-eslint#2148 where there was some disagreement about whether adding
this: void
to methods would slow down typescript, I'd like our documentation to be accurate if possible.So sorry for opening an issue for this, it just seemed weird to post a stack overflow question that very specifically was about another GitHub issue comment.
The text was updated successfully, but these errors were encountered: