typed-ember / ember-cli-typescript

Use TypeScript in your Ember.js apps!
https://docs.ember-cli-typescript.com
MIT License
363 stars 99 forks source link

@types/ember__utils: `typeOf()` won't accept object type #1475

Closed charlesfries closed 2 years ago

charlesfries commented 2 years ago

Seeing this error after bumping @types/ember__utils from ^3.16.2 to ^4.0.0

Which package(s) does this problem pertain to?

What are instructions we can follow to reproduce the issue?

ember new sample
cd sample
ember install ember-cli-typescript
ember g component -gc export

Add the following to the component class:

import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import { typeOf } from '@ember/utils';

export interface ExportComponentArgs {
  schema: Record<string, unknown>;
}

export default class ExportComponent extends Component<ExportComponentArgs> {
  constructor(owner: unknown, args: ExportComponentArgs) {
    super(owner, args);
    assert('<Export />: Must pass a schema object', typeOf(this.args.schema) === 'object'); // This condition will always return 'false' since the types '"function"' and '"object"' have no overlap.
  }
}

On the assert line, I am seeing the following TypeScript type error:

This condition will always return 'false' since the types '"function"' and '"object"' have no overlap.

schema is a Record type, but typeOf() thinks it should a function. Anyone know why?

chriskrycho commented 2 years ago

Ugh. I hate that type so much. I thought I had covered all the issues with it when making the updates, but apparently not. Thank you for the report! I'll try to poke at it next week.

chriskrycho commented 2 years ago

@charlesfries is this not still a problem?

charlesfries commented 2 years ago

I ended up rm -rf ing package-lock.json and node_modules after reading #1474 and the issue went away.

chriskrycho commented 2 years ago

Oh! That's really, really good to hear. 😅 (I hate this particular type.)