Skip to content

IData.value is explicitly of type string resulting in TypeScript incompatibility if an object is preferred #54

@NVRC

Description

@NVRC

Expected

interface IData {
  key: string;
  value: any;
} 

Actual

interface IData {
  key: string;
  value: string;
}

To reproduce with template linting rules

  1. Create an example project.
$ npx create-expo-app --template
Need to install the following packages:
  create-expo-app
Ok to proceed? (y) y
✔ Choose a template: › Blank (TypeScript)
✔ What is your app named? … example-app
...
$ cd example-app
$ npm install react-native-section-alphabet-list
  1. Define a list of objects e.g.
const data: Array<IData> = [
  { key: "0", value: {name: "Boston"}},
  { key: "1", value: {name:"Yellowknife"}}
]
  1. Note linting error:
(property) IData.value: string
Type '{ name: string; }' is not assignable to type 'string'.ts(2322)
types.d.ts(4, 5): The expected type comes from property 'value' which is declared here on type 'IData'

Proposal

Convert IData.value to a generic with a type of any used within the library to remain backwards compatible.
Overall this allows the module to be far more flexible by passing IData.value transparently to an overridden renderCustomItem prop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions