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

🛑 Remove .bind loss of type safety. #3147

Merged
merged 1 commit into from
Dec 21, 2017
Merged

Conversation

When you use .bind in typescript you [lose type safety](https://www.typescriptlang.org/play/#src=class%20Person%20%7B%0D%0A%20%20%20%20private%20name%3A%20string%3B%0D%0A%0D%0A%20%20%20%20speak(msg)%20%7B%0D%0A%20%20%20%20%20%20%20%20console.log(%60%24%7Bmsg%7D%20%24%7Bthis.name%7D%60)%0D%0A%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20look%20no%20exceptions!%0D%0A%20%20%20%20%20%20%20%20setTimeout(this.speak.bind(this)%2C%2010)%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Aclass%20PersonSafe%20%7B%0D%0A%20%20%20%20private%20name%3A%20string%3B%0D%0A%0D%0A%20%20%20%20speak(msg)%20%7B%0D%0A%20%20%20%20%20%20%20%20console.log(%60%24%7Bmsg%7D%20%24%7Bthis.name%7D%60)%0D%0A%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20look%20no%20exceptions!%0D%0A%20%20%20%20%20%20%20%20setTimeout(()%20%3D%3E%20this.speak()%2C%2010)%0D%0A%20%20%20%20%7D%0D%0A%7D

https://www.typescriptlang.org/play/#src=class%20Person%20%7B%0D%0A%20%20%20%20private%20name%3A%20string%3B%0D%0A%0D%0A%20%20%20%20speak(msg)%20%7B%0D%0A%20%20%20%20%20%20%20%20console.log(%60%24%7Bmsg%7D%20%24%7Bthis.name%7D%60)%0D%0A%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20look%20no%20exceptions!%0D%0A%20%20%20%20%20%20%20%20setTimeout(this.speak.bind(this)%2C%2010)%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Aclass%20PersonSafe%20%7B%0D%0A%20%20%20%20private%20name%3A%20string%3B%0D%0A%0D%0A%20%20%20%20speak(msg)%20%7B%0D%0A%20%20%20%20%20%20%20%20console.log(%60%24%7Bmsg%7D%20%24%7Bthis.name%7D%60)%0D%0A%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20look%20no%20exceptions!%0D%0A%20%20%20%20%20%20%20%20setTimeout(()%20%3D%3E%20this.speak()%2C%2010)%0D%0A%20%20%20%20%7D%0D%0A%7D)

By switching to an arrow function we get to retain the typescript engines type checking to avoid bugs slipping into releases when function signatures are changed.
@rxjs-bot
Copy link

rxjs-bot commented Dec 1, 2017

Warnings
⚠️

commit message does not follows conventional change log (1)

Messages
📖

(1) : RxJS uses conventional change log to generate changelog automatically. It seems some of commit messages are not following those, please check contributing guideline and update commit messages.

CJS: 1381.3KB, global: 750.6KB (gzipped: 120.4KB), min: 145.3KB (gzipped: 31.4KB)

Generated by 🚫 dangerJS

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0004%) to 97.079% when pulling c9c0a74 on samccone:patch-1 into 3390926 on ReactiveX:master.

@benlesh benlesh merged commit 6fee079 into ReactiveX:master Dec 21, 2017
@samccone samccone deleted the patch-1 branch December 22, 2017 00:47
@samccone
Copy link
Contributor Author

Thanks ben

@benlesh
Copy link
Member

benlesh commented Dec 28, 2017

👍

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants