The United States' top military officer twice called his Chinese counterpart to assure him the two nations would not suddenly go to war in the last weeks of Donald Trump's presidency, a senior defence official has said after the conversations were described in excerpts from a forthcoming book.

Fearful of Mr Trump's actions in the final stages of his administration, chairman of the joint chiefs of staff, General Mark Milley, told China's General Li Zuocheng the US would not strike.

One call took place on October 30, four days before the election that defeated Mr Trump. The second call was on January 8, two days after the insurrection at the US Capitol by supporters of the outgoing president.

Mr Trump said Mr Milley should be tried for treason if the report was true.

Mr Milley went so far as to promise Mr Li that he would warn his counterpart in the event of a US attack, according to the book Peril, written by Washington Post journalists Bob Woodward and Robert Costa.

"General Li, I want to assure you that the American government is stable and everything is going to be okay," Mr Milley told him in the first call, according to the book. "We are not going to attack or conduct any kinetic operations against you."

"If we're going to attack, I'm going to call you ahead of time. It's not going to be a surprise," Mr Milley reportedly said.

According to the defence official, who spoke on condition of anonymity, Mr Milley's message to Mr Li on both occasions was one of reassurance. The official questioned suggestions Mr Milley told Mr Li he would call him first, and instead said the chairman made the point that the US was not going to suddenly attack China without any warning - whether it be through diplomatic, administrative or military channels.

Mr Milley also spoke with a number of other defence chiefs around the world in the days after the January 6 riot, including military leaders from the UK, Russia and Pakistan. A readout of those calls in January referred to "several" other counterparts he spoke to with similar messages of reassurance that the US government was strong and in control.

The second call was meant to placate Chinese fears about the events of January 6. But the book reports Gen Li was not as easily assuaged, even after Mr Milley promised him: "We are 100 percent steady. Everything's fine. But democracy can be sloppy sometimes."

Mr Trump responded on Tuesday with a sharply worded statement dismissing Mr Milley as a "dumbass", and insisting he never considered attacking China.

Still, he said that if the report was true, "I assume he would be tried for TREASON in that he would have been dealing with his Chinese counterpart behind the President's back and telling China that he would be giving them notification 'of an attack'. Can't do that!"

"Actions should be taken immediately against Milley," Mr Trump said.

Mr Milley believed the president suffered a mental decline after the election, agreeing with a view shared by House Speaker Nancy Pelosi in a phone call they had on January 8, according to officials.

Ms Pelosi had previously said she spoke to Mr Milley that day about "available precautions" to prevent Mr Trump from initiating military action or ordering a nuclear launch, and she told colleagues she was given unspecified assurances that there were long-standing safeguards in place.

Mr Milley, according to the book, called the admiral overseeing the US Indo-Pacific Command, the military unit responsible for Asia and the Pacific region, and recommended postponing upcoming military exercises. He also asked senior officers to swear an "oath" that Mr Milley had to be involved if Mr Trump gave an order to launch nuclear weapons, according to the book.