ember-cli-typescript: [@types/ember bug] - ember types are broken in TypeScript 3.1
Which package(s) does this problem pertain to?
What are instructions we can follow to reproduce the issue?
npm install -g typescript@latest
tsc -v # make sure it's a v3.x (i.e. Version 3.1.0-dev.20180810)
git clone https://github.com/DefinitelyTyped/DefinitelyTyped
cd DefinitelyTyped
npm install
cd types/ember
tsc
Now about that bug. What did you expect to see?
I expected tsc to compile the ambient types and test files successfully
What happened instead?
test/array-ext.ts:16:32 - error TS2345: Argument of type 'ComputedProperty<Fix<Person & { name: string; }> | undefined, Fix<Person & { name: string; }> | undefined>'is not assignable to parameter of type 'Person'.
Property 'name' is missing in type 'ComputedProperty<Fix<Person & { name: string; }> | undefined, Fix<Person & { name: string; }> | undefined>'.
16 assertType<Person | undefined>(array.get('firstObject'));
NOTE
Switching to a TypeScript 2.x
npm install -g typescript@2
tsc
will compile the tests successfully and without error.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (15 by maintainers)
Fix for a variety of ember types has been merged
Ah, yes, the generic types need to be used somewhere. Otherwise a
ComputedProperty<foo>is structurally identical to aComputedProperty<bar>. I’m surprised it ever worked.I ran into an interesting situation where it looks like TypeScript may be discarding some information.
Currently our
Ember.ComputedPropertytype makes no use of the generics it receives. I’m guessing that the original intent was to sort of “tag” the CPs with information that can be extracted later.If we simplify this to the typical
BoxedtypeThis problem seems to be solved by using any generic anywhere
Thankfully the type in question is a class, so we can use a private field for this and no harm is done