question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@observable/@action + interface build error

See original GitHub issue

what did I do:

  1. create an empty react project with create-react-app --script-version=react-scripts-ts mobxtest and add deps: mobx & mobx-react
  2. add a intf.ts in src dir:
export interface ITest { // if ITest is a class, build passed
  a?: string
}

export class A {  // if A is an interface, build passed
}
  1. add a Store.ts in src dir:
import { action, observable } from 'mobx'
import { ITest } from './intf'

export class Store {
  @observable public t: ITest   // can't work with @observable
  @observable public testData: string = ''

  @action.bound
  public test(iTest: ITest) {  // can't work with @action.bound
    return this.testData = iTest.toString()
  }
  @action
  public test2 = (iTest: ITest) => {  // can't work with @action
    return this.testData = iTest.toString()
  }
}
export const store = new Store()
  1. use store in App.tsx
import * as React from 'react';
import './App.css';

import { observer } from 'mobx-react'
import logo from './logo.svg';
import { store } from './store'

@observer
class App extends React.Component {
  public render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        {store.testData}  // use store
      </div>
    );
  }
}
export default App;
  1. tsc compile success, but build with webpack report error: './intf' does not contain an export named 'ITest'

interface from file contains classes can’t work with @observable or @action

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mweststratecommented, Nov 30, 2018

@rainmanhhh I don’t see any error in the codesandbox you’ve linked. Please provide a better reproduction

0reactions
lock[bot]commented, Jul 21, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error with Actions observable in @ngrx/effects using ...
Error TS2345: Argument of type 'Actions' is not assignable to parameter of type 'Observable<Action>'. Types of property 'lift' are incompatible.
Read more >
Troubleshooting · redux-observable
Usually this means you're not returning an observable from one or more of your Epics. Often this is just a missing return ....
Read more >
Type definition of Epic<T = Action,S,D = any> is wrong? #392
I think Type definitions of redux-observable is wrong. export declare interface Epic<T extends Action, S, D = any> { (action$: ...
Read more >
Create an observable data action - Commerce | Dynamics 365
The IObservableAction interface returns an AsyncResult class that provides additional data including the status and error properties of the data ...
Read more >
Angular Basics: Introduction to Observables (RxJS)—Part 2
The subscriber class implements the observer interface. Therefore, a subscriber object has the next , error and complete methods.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found