Cannot find name when using action as type in method
See original GitHub issueI am trying to use this awesome library with @ngxs/store. Everything works fine except the type signature on action methods. When trying to use a generated ts-action
action Typescript shows the compile time error: Cannot find name 'ActionName'
.
See this stackblitz as demo: https://stackblitz.com/edit/angular-azg9at
import { State, StateContext, Action, Selector } from '@ngxs/store';
import { action, payload } from 'ts-action';
export const CreateModelAction = action('[App] CREATE MODEL', payload<AppModel>());
export interface AppModel {
id: number;
name?: string;
}
export interface AppStateModel {
models: AppModel[];
}
const DEFAULT_STATE: AppStateModel = {
models: []
};
@State({
name: 'app',
defaults: DEFAULT_STATE
})
export class AppState {
@Selector()
static models(state: AppStateModel) {
return state.models;
}
@Action(CreateModelAction)
createModel(ctx: StateContext<AppStateModel>, action: CreateModelAction) { // <-- this is the error here
ctx.patchState({
models: [
...ctx.getState().models,
action.payload
]
})
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Angular and Typescript: Can't find names - Error: cannot ...
Just use typescript 2.0 or higher and install @types/core-js with npm: ... Turns out some names changed with typings v1 vs the old...
Read more >Process Builder Deployment Error: “We can't find an action ...
When I try to deploy my changes to another sandbox have same problem "Error:(1, 1) Catch_Same_Products (Action) - We can't find an action...
Read more >TypeScript errors and how to fix them
A list of common TypeScript errors and how to fix them.
Read more >Usage With TypeScript
This page provides specific details for each of the different APIs included in Redux Toolkit and how to type them correctly with TypeScript....
Read more >TypeScript: JavaScript With Syntax For Types.
Let's take this incorrect JavaScript code, and see how TypeScript can catch mistakes in your editor. js. function compact ( ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually, if you are using TypeScript 2.8, the best way to solve the problem is with the new, built-in
InstanceType
type:I don’t think so,
action
has to return a constructor - not the constructed type.Anyway, there are some things that are much easier now, with TypeScript 2.8, so revisiting the implementation is on my todo list (to which I’ll add a reference to your question). It’s quite likely there will be some simplification (and breaking changes).