You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior:
Type should be narrowed to successfully call the action method
Actual behavior:
Error
Related Issues:
Code
exporttypeStepState<T={}>=T&{counter: number;confirm?: boolean;startingStep?: number};interfaceRepository{path: string;}interfaceState{repos: string|string[]|Repository|Repository[];createBranch?: string;}functionsteps(state: StepState<State>){if(state.repos!=null&&!Array.isArray(state.repos)){// Doesn't work without the cast, or the checks belowstate.repos=[state.repos]asstring[]|Repository[];// if (typeof state.repos === 'string') {// state.repos = [state.repos];// } else {// state.repos = [state.repos];// }}// With the cast above, this will be:// (property) State.repos: string[] | Repository[]state.repos;// But it can't be passed here, because it seems the type gets unnarrowed// Argument of type 'StepState<State>' is not assignable to parameter of type '{ counter: number; confirm?: boolean | undefined; startingStep?: number | undefined; } & { repos?: string[] | Repository[] | undefined; }'.// Type 'StepState<State>' is not assignable to type '{ repos?: string[] | Repository[] | undefined; }'.// Types of property 'repos' are incompatible.// Type 'string | Repository | string[] | Repository[]' is not assignable to type 'string[] | Repository[] | undefined'.// Type 'string' is not assignable to type 'string[] | Repository[] | undefined'.(2345)action(state);}functionaction<StateextendsStepState&{repos?: string[]|Repository[]}>(state: State){}
Output
functionsteps(state){if(state.repos!=null&&!Array.isArray(state.repos)){// Doesn't work without the cast, or the checks belowstate.repos=[state.repos];// if (typeof state.repos === 'string') {// state.repos = [state.repos];// } else {// state.repos = [state.repos];// }}// With the cast above, this will be:// (property) State.repos: string[] | Repository[]state.repos;// But it can't be passed here, because it seems the type gets unnarrowed// Argument of type 'StepState<State>' is not assignable to parameter of type '{ counter: number; confirm?: boolean | undefined; startingStep?: number | undefined; } & { repos?: string[] | Repository[] | undefined; }'.// Type 'StepState<State>' is not assignable to type '{ repos?: string[] | Repository[] | undefined; }'.// Types of property 'repos' are incompatible.// Type 'string | Repository | string[] | Repository[]' is not assignable to type 'string[] | Repository[] | undefined'.// Type 'string' is not assignable to type 'string[] | Repository[] | undefined'.(2345)action(state);}functionaction(state){}
TypeScript Version: 3.9.1-rc
Search Terms:
Expected behavior:
Type should be narrowed to successfully call the
action
methodActual behavior:
Error
Related Issues:
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: