🔎 Search Terms
"iterable", "literal", "method"
🕗 Version & Regression Information
- This is the behavior in every version I tried:
💻 Code
// Attribution: https://stackoverflow.com/a/75687384typeNonStringIterable<T>=Textendsstring ? never : TextendsIterable<any> ? T : never;declarefunctiondoSomething<T>(value: NonStringIterable<T>): T;consto={foo(){}};doSomething('value');doSomething(['v']);doSomething([o]);doSomething([{foo(){}}]);🙁 Actual behavior
consto={foo(){}};doSomething('value');// ~~~~~~~// Argument of type 'string' is not assignable to parameter of type 'never'. (2345)// (correct)doSomething(['v']);// Fine (correct)doSomething([o]);// Also fine (correct)doSomething([{foo(){}}]);// ~~~~~~~~~~~~~~// Argument of type '{ foo(): void; }[]' is not assignable to parameter of type 'never'. (2345)// (incorrect)doSomething([o]) works correctly, yet directly passing the same object as o causes an error. This error happens regardless of the method being deeply nested or not. Interestingly, empty object ({}) and arrow function ({ foo: () => {} }) are fine. The same goes with a separately declared method.
🙂 Expected behavior
Only the first example should cause an error.
🔎 Search Terms
"iterable", "literal", "method"
🕗 Version & Regression Information
💻 Code
🙁 Actual behavior
doSomething([o])works correctly, yet directly passing the same object asocauses an error. This error happens regardless of the method being deeply nested or not. Interestingly, empty object ({}) and arrow function ({ foo: () => {} }) are fine. The same goes with a separately declared method.🙂 Expected behavior
Only the first example should cause an error.