What should the type of image be for new architecture when using Typescript? #72
-
Hello everyone! I have the callstack/react-native-slider already migrated to new architecture. I have an issue with type for an image: /**
* @see https://reactnative.dev/docs/image#source
*/
export type ImageSourcePropType = ImageURISource | ImageURISource[] | ImageRequireSource; But it looks like the Codegen has problem with this type:
and ineed, looking at the sources I can see that the for images there's still the case 'ImageSource':
return {
type: 'ReservedPropTypeAnnotation',
name: 'ImageSourcePrimitive',
}; (taken from react-native-codefen/src/parsers/typescript/components/props.js) I don't think I can still use the import type {ImageSource} from 'react-native/Libraries/Image/ImageSource'; ends with So my question is: what type should be used for Typescript with new architecture codegen? Any support with this would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Probably here you have an answer |
Beta Was this translation helpful? Give feedback.
-
The real answer is that, probably, You are already using the right type for TS, but the CodeGen is not aware of the TS ImageSource. But this is a great opportunity to contribute! :D How?We can try to add a proper support for that type in TypeScript. The truth is that, probably, the TS AST Parser outputs type that is not
For example, we can create a very simple component spec in TS with just an ImageSource, run the codegen and see what is output by the parser. To run a piece of the codegen singularly, the parser, for example, you can use this command:
When it works properly, the Codegen outputs the schema. In this case, we are not supporting the type yet, so it will probably output an error.
We can open the
What do you think? If you want to go through this path, we would be extremely happy to review the PR and import it! :D |
Beta Was this translation helpful? Give feedback.
The real answer is that, probably, You are already using the right type for TS, but the CodeGen is not aware of the TS ImageSource.
The TypeScript parser is a porting of the Flow one: we use Flow extensively internally, but we don't use TypeScript. So the TS parser could have bugs and incompatibilities, unfortunately.
But this is a great opportunity to contribute! :D
How?
We can try to add a proper support for that type in TypeScript.
The truth is that, probably, the TS AST Parser outputs type that is not
ImageSource
when it encounter that type.