1

Am working on angular 13 version.Trying to import and use action file inside a .spec file shows an error like below

Cannot use namespace 'MyActions' as a type.ts(2709)

This is my spec file

import * as MyActions from '../../core/store/action/my.actions';
describe('MyActionComponent', () => {
  let myActions: MyActions;

Please excuse for full source code.

Thanks in advance

luiscla27
  • 4,956
  • 37
  • 49
arj
  • 887
  • 1
  • 15
  • 37
  • MyAction is a namespace and not a type. Use an exporting interface of the namespace like `let myActions: MyAction.SomeActionType` – Deitsch Apr 04 '22 at 13:00
  • @Deitsch it showing some other issue – arj Apr 04 '22 at 13:26
  • What is the error now? – Deitsch Apr 04 '22 at 13:32
  • @Deitsch MyActions.loadMyActionSuccess' refers to a value, but is being used as a type here. Did you mean 'typeof MyActions.loadMyActionSuccess'?ts(2749) – arj Apr 04 '22 at 14:05
  • If you want to assign a value use the `=` operator. `:` is used for specifying a type. Also please edit your question and add the `MyActions` namespace so we can discuss this better. – Deitsch Apr 04 '22 at 14:42

1 Answers1

0

MyAction is a namespace and not a type, hence the error. You object can only be of type coming from said namespace (or any other namespace). You may want to use an exporting interface of the namespace:

import * as MyActions from '../../core/store/action/my.actions';

describe('MyActionComponent', () => {
    let myActions: MyAction.SomeInterface
    ...
});
Deitsch
  • 1,610
  • 14
  • 28