You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// defined overload typetypeMyOL={(x:1):1;(x:2):2;(x:3):3;}constmyfa:MyOL=(a:1|2|3)=>{// ~~~~// Type '(a: 1 | 2 | 3) => 1 | 2 | 3 | undefined' is not assignable to type 'MyOL'.// Type '1 | 2 | 3 | undefined' is not assignable to type '1'.// Type 'undefined' is not assignable to type '1'.ts(2322)switch(a){case1: return1;case2: return2;case3: return3;}a;// never, Unreachable code detected.ts(7027)}constmyfb:MyOL=(a:1|2|3)=>{// ~~~~// Type '(a: 1 | 2 | 3) => 1 | 2 | 3 | undefined' is not assignable to type 'MyOL'.// Type '1 | 2 | 3 | undefined' is not assignable to type '1'.// Type 'undefined' is not assignable to type '1'.ts(2322)// ~~~~~~~~~~~~~~// Not all code paths return a value.(7030) (on `(a:1|2|3) => {`)if(a===1)return1;if(a===2)return2;if(a===3)return3;a;// never, but not shown as unreachable}constmyfc: typeofmyfd=(a:1|2|3)=>{// no error// ~~~~// Type '(a: 1 | 2 | 3) => 1 | 2 | 3' is not assignable to type '{ (a: 1): 1; (a: 2): 2; (a: 3): 3; }'.// Type '1 | 2 | 3' is not assignable to type '1'.// Type '2' is not assignable to type '1'.(2322)switch(a){case1: return1;case2: return2;case3: return3;}}// declared overload function version has no problemfunctionmyfd(a:1):1;functionmyfd(a:2):2;functionmyfd(a:3):3;functionmyfd(a:1|2|3){// no errorswitch(a){case1: return1;case2: return2;case3: return3;}}
π Actual behavior
Errors on the implementations of myfa and myfb and myfc, which are typed by a defined function overload type.
However, no errors on the declared function overload myfd.
The text was updated successfully, but these errors were encountered:
craigphicks
changed the title
Inability to exhaustively list cases of parameter in function implementation when type is a defined overload type (as opposed to declared overload type
Errors on the implementation for a defined overload type (c.f., no errors on declared implementation)
Jan 6, 2024
Duplicate of #47669. Arrow functions do not support overloading yet.
craigphicks
changed the title
Errors on the implementation for a defined overload type (c.f., no errors on declared implementation)
Duplicate of #47669. Arrow functions do not support overloading yet.
Jan 6, 2024
π Search Terms
is: issue: in-title: defined overload type
is:issue label:bug in-title: overload type
π Version & Regression Information
Same in versions 3.75 ~ 5.3.3
Slight differences in errors before that.
β― Playground Link
https://www.typescriptlang.org/play?ts=3.7.5&ssl=24&ssc=27&pln=23&pc=27#code/PTAEBMFMDMEsDtLlAewG6QE4BsUENkAXATwAdIAoE80AWWIHkAZUAXlFAG8KOOAKAB4AuAIwBKUQG4evQUIBME+dN6g5AZgnrpAXwoUAxingBnQqAC2xaHiH1mbNbZEAfeS81sAfFwohVAH5BAX5gACpkkKAA5Hy2oCKgLqDySaCerD6JyanJ6mkArvBQcIjg0aCwJqDwKOZ4JiawAObweABG2FGEKKDUUdH2TNEAdKG8ETTR2Slp+clFJQhIFVU1daANTa0dXX29-TEio+OqkwOLMMvlldW19Y0tbZ3dB5FHo4QmfPLq8ooyDgmADusEIBgAFnExJxQAYGlEREJQJhIIQCph4AlJHCESlkaj0ZiUjj4SYouoCWiMVjtKA9Ko8Dj-IgMJgADSgACq8FReEhuyiRigEDRkAMhCQIy+fAA7AAGeSysQUPRGUzmKzQdp2RgsdhxURuDxiby+fy8YIhfznGKGhJpXLpU2ZB05OaFYpXMqrO4bLZPQX7PrvQZ6k4W0C26aOj0LL2lFa3dYPbbPPY9ENTY5jSMcaOXRM3Nb3TaPHYvYOHaafb6-f4qvOqZuWq1tq3jABy-uw2DhKBFpDwhAh1UJNM2oDQeGwBUgIzl8vU8tNfGMoAABobXO4Mj5OBuVapYNAnGxWOxxCjqcSRCpeCezxf2Ipr0SscpAZVT3Fz+xPOOxLaF+TKgCykBspy7QFOYpYmBCKDAliDSgEUfICi8qr6OqZiWNYBjIv0KCnlqyAGs4xqaJksIsr0WCYCgmCnBwHY2qG9ozE6e5urMeS+imZZpkGmbVrCHESNiTjIoo0k4vamjInSOgRmA+ahpxcz8aWAYVhmbzZipzbRvIWn+uW6avFmAw5j8fwAqoIJgpC0KwmSiJUu+klufib4TsouLkukHkTkpWHjFABjYHgqLIOgWC4AQoDQEUEqwOubJNOuEIobUoCkAxLwWBQyXwKl66kduEh3sVKWEGlWIVbYMmfiVZUNdY4CGgpwGtXV5UddulEwmBYC5fRjFfo54JQngw3eUivm3qSeLyMFxL+d5lKLbSOJ6HoFBAA
π» Code
π Actual behavior
Errors on the implementations of
myfa
andmyfb
andmyfc
, which are typed by a defined function overload type.However, no errors on the declared function overload
myfd
.π Expected behavior
No errors at all.
Additional information about the issue
Workaround:
Advice welcome on a better title.
The text was updated successfully, but these errors were encountered: