Taiwan's exports rose in June on sustained demand for technology products even as shipments to China weakened, and the government said the outlook was good as companies ramp up for the end-of-year holiday season despite concerns over Ukraine and inflation.

Exports rose 15.2% in June from a year earlier to $42.2 billion, the Ministry of Finance said on Friday, the second-highest monthly amount on record and up for the 24th consecutive month.

That was faster than the 12.5% rise recorded in May, and better than the 13.55% expansion forecast from a Reuters survey of analysts.

The ministry attributed the June growth to strong technology demand, especially for chips, with supply chain problems easing.

However, June exports to China, Taiwan's largest trading partner, shrank an annual 4.5% to $15.43 billion, after a 0.8% rise in May, suggesting some continuing drag on China's economy from disruptions caused by COVID-19 outbreaks.

Overall exports of electronics components rose 19% in June to $17.27 billion, the second-highest monthly figure on record, with semiconductor exports jumping 21.2% from a year earlier.

Many companies expect global chip shortages to last at least for the rest of the year, which will continue to bolster Taiwanese semiconductor firms' order books.

Firms such as TSMC, the world's largest contract chipmaker, are major suppliers to Apple Inc and other global tech giants, as well as providers of chips for auto companies and lower-end consumer electronics.

Earlier on Friday, TSMC -- the majority of whose factories are in Taiwan -- reported an 18.5% on-year rise in June revenues, with first-half revenues soaring 39.6% compared to the same period last year.

The finance ministry warned of continued uncertainty over the war in Ukraine and inflationary pressures, but said the outlook remained bright, with strong demand for semiconductors and the peak export season about to begin for the year-end holidays in the West.

Exports to the United States were up 27.9%, much faster than a 15.5% jump recorded the previous month.

China will release its June trade data next week, with investors focusing on how quickly its economy and supply chains can recover from COVID lockdown shocks this spring.

Taiwan's June imports rose 19.2% to $37.56 billion, the third-highest monthly figure on record, though worse than economists' expectations of a 24% jump, after an increase of 26.7% in May.

Taiwan could see July exports increase by 10% to 13% from a year earlier, the finance ministry said. (Reporting by Jeanny Kao, Yimou Lee and Ben Blanchard; Editing by Sonali Desai)