CLI-only error calling generic function
See original GitHub issueTypeScript Version: 3.2.0-dev.20181002
Code
function getFirst<K extends string, T>(obj: Record<K, ReadonlyArray<T>>, key: K): T {
return obj[key][0];
}
interface I {
readonly n: ReadonlyArray<number>;
readonly s: ReadonlyArray<string>;
}
function f(i: I): number {
return getFirst(i, "n");
}
Expected behavior:
No error.
Actual behavior:
No error in the editor. Error on the command line:
src/a.ts:11:20 - error TS2345: Argument of type 'I' is not assignable to parameter of type 'Record<"n", ReadonlyArray<string>>'.
Types of property 'n' are incompatible.
Type 'ReadonlyArray<number>' is not assignable to type 'ReadonlyArray<string>'.
Type 'number' is not assignable to type 'string'.
11 return getFirst(i, "n");
Related Issues: #19686
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
c++-cli: Why does calling a generic function fail, when it calls ...
After some testing, I just found a solution to this specific problem: I need to define func1g as follows: generic <class T> void...
Read more >"All call to function are unreachable" for templated functions
It happens frequently that on templated functions I get this error, but it's silly because, ... OS Linux(amd64) v5.11.0-38-generic, screens 1920.0x1200.0.
Read more >Confused about calls to generic function : r/fsharp - Reddit
So I'm trying to call this generic function 2 times with different types but the second time, it expects the first type. Can...
Read more >CLion error (HardwareSerial0) - PlatformIO Community
I made an integration with CLion, I did a brand new project (because ... HardwareSerial0.cpp.o (symbol from plugin): In function `Serial': ...
Read more >Practical heuristics to improve precision for erroneous function ...
This helps guard against a bad call to the function if the user specified the arguments out of order, resulting in compile-time errors....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Whats the ‘take the first type’ motivation? (Looks like a can of worms to me)
Rewritten version that is stable between CLI/server