Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

Type annotations can only be used in TypeScript files. ts(8010)

$
0
0

I'm following a tutorial (link to tutorial below) on setting up an IAP (In-App-Purchase) for a react native app. While writing the code, vs code is warning me that "Type Annotations can only be used in TypeScript files", this warned under the "purchase: InAppPurchase | SubscriptionPurchase" and "error: PurchaseError" part of the code. When looking into this, the most popular solution I could find (on Stack Overflow or elswhere) was to simply disable the 'TypeScript and JavaScript Language Features'.

I don't feel like that solves the problem, but I'm not sure. Would disabling this solve the problem and let my app run as expected? Or is there is another way to include this typescript syntax in my javascript file?

    useEffect(() => {    purchaseUpdateSubscription = RNIap.purchaseUpdatedListener(        async (purchase: InAppPurchase | SubscriptionPurchase) => {            const receipt = purchase.transactionReceipt;            if (receipt) {                try {                    if (Platform.os === 'ios') {                        RNIap.finishTransactionIOS(purchase.transactionReceipt)                    }                    await RNIap.finishTransaction(purchase)                    await processNewPurchase(purchase)                } catch (ackErr) {                    console.log('ackErr', ackErr)                }            }        }    );    purchaseErrorSubscription = RNIap.purchaseErrorListener(        (error: PurchaseError) => {            console.log('purchaseErrorListener', error)        }    );    return (() => {        if (purchaseUpdateSubscription) {            purchaseUpdateSubscription.remove()            purchaseUpdateSubscription = null;        }        if (purchaseErrorSubscription) {            purchaseErrorSubscription.remove()            purchaseUpdateSubscription = null;        }    })}, [])

link to tutorial: https://medium.com/@rossbulat/react-native-subscriptions-with-in-app-purchases-setup-fdaf3863e07f


Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>