-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Compiler is forgetting the basetype of an extended type when that type is generic #28280
Comments
ES2015 is es6. When es6 was published they formally started a by-year versioning scheme; so es6 and es2015 are synonymous. |
Secondly: An interface cannot inherit from a variable type parameter. If you want similar behavior, you want to use intersection types, like so: type TExtObj = TObj & {
newAttr: any
} Thirdly: Capital Fourth: Spreads are currently limited to concrete types - you cannot spread a generic. This will change in 3.2, thanks to #28234. |
Well, this is embarassing. Other than what you might think I am capable of performing a google search, so when i got an
Well yeah, thats more or less what I'm saying. Do you mean to say that this is by design? Why would you want to do that? Note that the variable type will always be an extension of object. The problem is that the compiler isnt smart enough to notice that, at least from what I think to see there. Thanks for the hint with the intersection types. It could very well work, I'll try and report back.
Using
Good to know, thanks. Hard to test though, as the issue described above is causing issues (Compiler specifically says that its not an object not only upon use of the spread operator but also the interface inheritance.), and here the Compiler of course already resolved it: const genTypeFactory = <T>(param: T) => {
return param;
}
const reWrapped = {...genTypeFactory({attr: "someVal"})} EDIT: Actually I just tested it with the 3.2.0-dev.20181101. The spread-issue is gone indeed, the other issues remain. And the spread operation wasnt really a problem of mine, It was just something I tried to see if other operations I'd expect to work on an object worked. |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
I have only done TS for about a 3/4 of a month, and JS for less than 2 months, so maybe I'm just doing someting fundamentally wrong, but after questioning people that have done this for some time I think these are some compiler-issues.
On an somewhat related note, if any of you managed to implement the 'Basic example' from here in TS without errors or using //@ts-ignore please let me know. Also why is 'Proxy' in the ES2015 lib and not in the 'ES6' lib, and whats the difference between these libs?
TypeScript Version: 3.1.5 and 3.2.0-dev.20181101
Search Terms: generic, extend, extended, base-type, basetype, type
Code
Expected behavior:
Compiles without error
Actual behavior:
Throws TS2312 and TS2698
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: