Exports edged down 0.5% in October from a year earlier to $39.93 billion, the Ministry of Finance said on Tuesday.

That was better than a forecast for a 6% contraction in a Reuters poll, and followed a 5.3% drop in September - the first contraction in more than two years.

The ministry said while global demand overall was slowing, tech exports were holding up well, helped by demand for high-performance computing, autos and data centres.

Taiwan's total exports of electronics components in October rose 15.9% to $16.9 billion, with semiconductor exports up 19.4% 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 even as demand for some consumer electronics weakens.

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 goods.

United Microelectronics Corp, a smaller competitor of TSMC, this week reported October sales jumped 27.1% year-on-year.

Still, Taiwan's exports to China, the island's largest trading partner, fell an annual 9.2% to $14.72 billion in October, after a 13.3% drop in September.

China's exports and imports unexpectedly contracted in October, the first simultaneous slump since May 2020, as surging inflation and rising interest rates hammered global demand while new COVID-19 curbs at home disrupted output and consumption.

While Taiwan's finance ministry expected demand for chips in tech products ahead of the end-of-year shopping season to help maintain the export momentum, it said global inflation, monetary tightening, China-U.S. tensions and the Russia-Ukraine war would "continue to deepen doubts about the international economic outlook".

"This may constrain our country's export performance in the fourth quarter," it added.

The fourth quarter is traditionally the hot season for Taiwan's tech companies as they race to supply cellphones, tablets and other electronics for the year-end holiday period in Western markets.

October exports to the United States were up 3.1%, compared with the 2.1% contraction recorded the previous month.

Taiwan's October imports rose 8.2% to $36.95 billion, driven by energy and semiconductor equipment, compared with economists' expectations of a 3.5% drop and after a fall of 2.4% in September.

Taiwan could see November exports contract in a range of 5% to 8% from a year earlier, the finance ministry said.

(Reporting by Emily Chan and Ben Blanchard; Editing by Ana Nicolaci da Costa)