Ionic-framework: bug: ion-range event value is always type RangeValue {lower, upper}.

Created on 25 Sep 2019  路  3Comments  路  Source: ionic-team/ionic-framework

Bug Report

Ionic version:
[x] 4.x

Current behavior:
The type of the ion-range value is always RangeValue ({ lower: number; upper: number; }).

Type 'RangeValue' is not assignable to type 'number'.
  Type '{ lower: number; upper: number; }' is not assignable to type 'number'.ts(2322)

Expected behavior:
But by the docs it should be number OR RangeValue (number | { lower: number; upper: number; })

Steps to reproduce:
Create a ion-range and append ionChange event. Please see related code...

Related code:

html

<ion-range
  (ionChange)="onRangeChange($event)"
  [min]="min"
  [max]="max"
  debounce="500"
></ion-range>

ts (error visible, see Current behavior section.)

onRangeChange(event: IonRange) {
  this.value = event.value;
}

Other information:
Workaround: Cast to number. But maybe it's unsafe.

I think it's just a type definition issue.

Ionic info:

Ionic CLI :     5.2.8
Ionic Angular : 4.9.1
NodeJS :        v10.15.3
npm :           6.4.1
OS :            Windows 10
VSCode :        1.38.1
core bug

Most helpful comment

I can confirm this is still present in the latest @ionic/angular version (5.0.7)

All 3 comments

I can confirm this is still present in the latest @ionic/angular version (5.0.7)

Thanks for the issue! I was able to reproduce this. It seems to be because we export the value as RangeValue here: https://github.com/ionic-team/ionic-framework/blob/master/core/src/components/range/range-interface.ts#L6

It doesn't seem like we do this in any other case:

As a workaround, casting it to number works or setting the type for value to RangeValue:

import { RangeValue } from '@ionic/core';

@Component({
   ...
})
export class SomePage {
  value: RangeValue;

}

@liamdebeasi Do you see any issues with changing this?

Any update on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexbainbridge picture alexbainbridge  路  3Comments

vswarte picture vswarte  路  3Comments

masimplo picture masimplo  路  3Comments

brandyscarney picture brandyscarney  路  3Comments

gio82 picture gio82  路  3Comments