6 ms·
Alas, no: foo.ts:1:10 - error TS2393: Duplicate function implementation.
by codebje 10mo ago
Alas, no:
foo.ts:1:10 - error TS2393: Duplicate function implementation.
- wk_end 10mo agoLike this: https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABAWwJ4DFwQBQA8BciUATiAKYCUhYIyARmcQNwBQoksCKGWehwAQwA2AZ0qERJGGADmrdtHhI0mSH0R04cIWQFgqiGvUaIAPoknFpMxAG8WiR4hjBEeCnYdPvxMlBDESAAsAEys3gC+iGSiZJ7ePn4BSABEABIxQnAp4U4RLPlsWJxIIGIAasLk6prauvrxTi5uuB72CU6+-oGIKQAqABZxRgzERDDIZCJEAO5whCmIANRuKrytiABUiCEUuY5RMWKNHV3JvYNxkyIiAjJxMCILy9yqOK37iPn5QA https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABA... It's a bit of a hack, though - if you incorrectly implement myFunc so that, say, it returns a string even when x is true, it can violate the overloading assertions without any error or warning.
- codebje 10mo agoThanks! If anyone else is playing along, to get this to work with tsc I needed to use "--strict". Being able to use a function along those lines in a type safe manner is still pretty nifty, even if you can't write it with type safety.