Conversation
TypeScript forbids static members from using the class type parameter, which broke consumer tsc since 1.16.5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type
Itemastypeof PickerItemwith a genericPickerItemclass, matchingPickerIOSandstatic Item: typeof PickerItem = PickerIteminjs/Picker.js.PickerProps<T>/onValueChangeare unchanged.Fixes #307
Also covers #339
Summary
static Item: React.ComponentType<PickerItemProps<T>>is invalid TypeScript (TS2302: static members cannot reference class type parameters). TypeScript documents this at https://www.typescriptlang.org/docs/handbook/2/classes.html#type-parameters-in-static-membersSame error as #216. #222 fixed it by using
ItemValue; #302 (v1.16.5) putTback onItemand the error returned. Still present on current main. Consumers that leaveskipLibCheckat the default (false) fail; this repo'stscjob did not catch it becausetsconfig.jsonsets"skipLibCheck": true.validate:typescriptnow also runs a check that typecheckstypings/withskipLibCheck: falseand only asserts diagnostics in that folder, so this error cannot silently return.The class is used instead of
static Item: React.ComponentType<PickerItemProps<ItemValue>>(the #222 one-liner). The one-liner is enough to clear TS2302 and is what #216 confirmed. The class is the same Item-class pattern already in this repo, andPicker.Itemstays generic (the intent of #302) without namingPicker'sTon a static. Can switch to the one-liner if that is preferred.Test plan
yarn validate:typescriptpassesskipLibCheck: true,tscno longer reportsTS2302fromnode_modules/@react-native-picker/picker/typings/Picker.d.ts<Picker.Item label="Java" value="java" />still typechecksPickerselectedValue/onValueChangegenerics still infer