Add TypeScript support
codeAbinash opened this issue · 5 comments
codeAbinash commented
Add TypeScript support
gfaraj commented
Please add this!
Intellectus-Jiwon commented
I WANT IT!💪
alhiwatan commented
It was long due, but we've finally released the TypeScript version.
https://dash.applovin.com/documentation/mediation/react-native/getting-started/migration6
padge commented
@alhiwatan Thanks for adding types!
I ran into some issues though, in that I'm getting type errors when running tsc on my project. Here is the output I'm getting using TypeScript v5.2.2:
$ tsc --noEmit
../../node_modules/react-native-applovin-max/src/AdView.tsx:247:13 - error TS2322: Type '{ children?: React.ReactNode; hitSlop?: Insets | undefined; id?: string | undefined; onLayout?: ((event: LayoutChangeEvent) => void) | undefined; ... 78 more ...; accessibilityLanguage?: string | undefined; }' is not assignable to type 'StyleProp<ViewStyle>'.
Type '{ children?: React.ReactNode; hitSlop?: Insets | undefined; id?: string | undefined; onLayout?: ((event: LayoutChangeEvent) => void) | undefined; ... 78 more ...; accessibilityLanguage?: string | undefined; }' is not assignable to type 'undefined'.
247 style={{ ...(style as ViewProps), ...dimensions }}
~~~~~
../../node_modules/react-native/Libraries/Components/View/ViewPropTypes.d.ts:234:3
234 style?: StyleProp<ViewStyle> | undefined;
~~~~~
The expected type comes from property 'style' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<AdProps & { adFormat: AdFormat; adaptiveBannerEnabled?: boolean | undefined; autoRefresh?: boolean | undefined; onAdExpanded?: ((adInfo: AdInfo) => void) | undefined; onAdCollapsed?: ((adInfo: AdInfo) => void) | undefined; } & ViewProps & AdViewNativeEvents, {...'
../../node_modules/react-native-applovin-max/src/TargetingData.ts:60:9 - error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
60 get yearOfBirth(): Promise<number> {
~~~~~~~~~~~
../../node_modules/react-native-applovin-max/src/TargetingData.ts:79:9 - error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
79 get gender(): Promise<UserGender> {
~~~~~~
../../node_modules/react-native-applovin-max/src/TargetingData.ts:100:9 - error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
100 get maximumAdContentRating(): Promise<AdContentRating> {
~~~~~~~~~~~~~~~~~~~~~~
../../node_modules/react-native-applovin-max/src/TargetingData.ts:116:9 - error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
116 get email(): Promise<string | null> {
~~~~~
../../node_modules/react-native-applovin-max/src/TargetingData.ts:130:9 - error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
130 get phoneNumber(): Promise<string | null> {
~~~~~~~~~~~
../../node_modules/react-native-applovin-max/src/TargetingData.ts:144:9 - error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
Type 'Promise<string[] | null>' is missing the following properties from type 'string[]': length, pop, push, concat, and 29 more.
144 get keywords(): Promise<string[] | null> {
~~~~~~~~
../../node_modules/react-native-applovin-max/src/TargetingData.ts:158:9 - error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
158 get interests(): Promise<string[] | null> {
~~~~~~~~~
Found 8 errors in 2 files.
Errors Files
1 ../../node_modules/react-native-applovin-max/src/AdView.tsx:247
7 ../../node_modules/react-native-applovin-max/src/TargetingData.ts:60
Are you able to build the typescript into *.js
files, with the corresponding *.d.ts
declaration files? I think that would resolve the issue.
alhiwatan commented
@padge, thanks for reporting the issues. Would you mind trying this out? I can't reproduce the issues, but I think this is what causes them.
diff --git a/src/AdView.tsx b/src/AdView.tsx
index 1a031ec..21b014e 100644
--- a/src/AdView.tsx
+++ b/src/AdView.tsx
@@ -244,7 +244,7 @@ export const AdView = ({
onAdExpandedEvent={onAdExpandedEvent}
onAdCollapsedEvent={onAdCollapsedEvent}
onAdRevenuePaidEvent={onAdRevenuePaidEvent}
- style={{ ...(style as ViewProps), ...dimensions }}
+ style={Object.assign({}, style, dimensions)}
{...otherProps}
/>
);
diff --git a/src/TargetingData.ts b/src/TargetingData.ts
index d5a58f6..1c2963d 100644
--- a/src/TargetingData.ts
+++ b/src/TargetingData.ts
@@ -50,21 +50,21 @@ export const TargetingData = {
/**
* Sets the year of birth of the user. Sets 0 to clear this value.
*/
- set yearOfBirth(value: number) {
+ set yearOfBirth(value: number | Promise<number>) {
nativeMethods.setTargetingDataYearOfBirth(value);
},
/**
* Gets the year of birth of the user.
*/
- get yearOfBirth(): Promise<number> {
+ get yearOfBirth(): number | Promise<number> {
return nativeMethods.getTargetingDataYearOfBirth();
},
/**
* Sets the gender of the user. Sets {UserGender.Unknown} to clear this value.
*/
- set gender(value: UserGender) {
+ set gender(value: UserGender | Promise<UserGender> ) {
if (value === UserGender.Unknown ||
value === UserGender.Female ||
value === UserGender.Male ||
@@ -76,7 +76,7 @@ export const TargetingData = {
/**
* Gets the gender of the user.
*/
- get gender(): Promise<UserGender> {
+ get gender(): UserGender | Promise<UserGender> {
return nativeMethods.getTargetingDataGender().then((value: string) => {
return value as UserGender;
});
@@ -85,7 +85,7 @@ export const TargetingData = {
/**
* Sets the maximum ad content rating shown to the user. Sets {AdContentRating.None} to clear this value.
*/
- set maximumAdContentRating(value: AdContentRating) {
+ set maximumAdContentRating(value: AdContentRating | Promise<AdContentRating> ) {
if (value === AdContentRating.None ||
value === AdContentRating.AllAudiences ||
value === AdContentRating.EveryoneOverTwelve ||
@@ -97,7 +97,7 @@ export const TargetingData = {
/**
* Gets the maximum ad content rating shown to the user.
*/
- get maximumAdContentRating(): Promise<AdContentRating> {
+ get maximumAdContentRating(): AdContentRating | Promise<AdContentRating> {
return nativeMethods.getTargetingDataMaximumAdContentRating().then((value: number) => {
return value as AdContentRating;
});
@@ -106,56 +106,56 @@ export const TargetingData = {
/**
* Sets the email of the user. Sets null to clear this value.
*/
- set email(value: string | null) {
+ set email(value: string | null | Promise<string | null> ) {
nativeMethods.setTargetingDataEmail(value);
},
/**
* Gets the email of the user.
*/
- get email(): Promise<string | null> {
+ get email(): string | null | Promise<string | null> {
return nativeMethods.getTargetingDataEmail();
},
/**
* Sets the phone number of the user. Sets null to clear this value.
*/
- set phoneNumber(value: string | null) {
+ set phoneNumber(value: string | null | Promise<string | null> ) {
nativeMethods.setTargetingDataPhoneNumber(value);
},
/**
* Gets the phone number of the user.
*/
- get phoneNumber(): Promise<string | null> {
+ get phoneNumber(): string | null | Promise<string | null> {
return nativeMethods.getTargetingDataPhoneNumber();
},
/**
* Sets the keywords describing the application. Sets null to clear this value.
*/
- set keywords(value: string[] | null) {
+ set keywords(value: string[] | null | Promise<string[] | null> ) {
nativeMethods.setTargetingDataKeywords(value);
},
/**
* Gets the keywords describing the application.
*/
- get keywords(): Promise<string[] | null> {
+ get keywords(): string[] | null | Promise<string[] | null> {
return nativeMethods.getTargetingDataKeywords();
},
/**
* Sets the interests of the user. Sets null to clear this value.
*/
- set interests(value: string[] | null) {
+ set interests(value: string[] | null | Promise<string[] | null> ) {
nativeMethods.setTargetingDataInterests(value);
},
/**
* Gets the interests of the user.
*/
- get interests(): Promise<string[] | null> {
+ get interests(): string[] | null | Promise<string[] | null> {
return nativeMethods.getTargetingDataInterests();
},