Mayors in at least seven major U.S. cities reaffirmed their commitments to shelter illegal immigrants from federal immigration authorities after Republican president-elect Donald Trump said he would block federal funding for “sanctuary cities.”

Sanctuary policies vary by city. Typically, local police refrain from helping federal authorities identify undocumented immigrants for deportation, unless they have committed serious crimes.

The San Francisco-based Immigrant Legal Resource Center counts five state-level laws or policies, 365 county policies or ordinances, and 37 city-level policies putting some limits on these requests.

Following Trump’s election, Democratic mayors in cities including New York, Chicago, Los Angeles, Seattle, Philadelphia, San Francisco and Providence, R.I., among others, said they would challenge any Trump administration move to crack down on illegal immigration.

Many billions of dollars could be at stake. For instance, San Francisco alone gets about $1 billion annually from the federal government, both directly and through the state, according to Ben Rosenfield, the controller for the city and county. The city is “assessing budget impacts from possible federal actions,” but support for public health and human service programs could be affected, he said.

Presidents have limited powers to strip federal funding from local governments without the express approval of Congress, say legal experts. This is especially true in regard to mandatory expenditure programs, like Medicaid.

The Trump administration would have more leeway to suspend or slow the allocation of discretionary grants, particularly those related to criminal justice and dispensed by the Justice Department or the Department of Homeland Security, said George Washington University constitutional law professor Jonathan Turley.

With those funds, “there’s a great deal the Trump administration could do to carry out the threat,” he said. The Trump administration could also steer more grant money to cities that cooperate with federal immigration laws, he said.

Presidential spending power has been a contentious area of law, especially during the Obama administration, and Mr. Turley said he would expect that cities would go to court to challenge any effort to financially punish them for sheltering undocumented immigrants.

Immigration and Customs Enforcement can enforce federal immigration law without cooperation from local authorities but protective policies at the local level make the agency’s job more challenging.

At issue in many localities is a practice by the Department of Homeland Security to identify a potentially deportable individual in jails and issue a “detainer,” which can extend detention even for low-level offenders.

Some cities argue it isn’t their role to enforce immigration laws and doing so sows distrust between communities and police. Some courts have ruled against the use of detainer requests. The Northern District of Illinois ruled in October that detainer requests by the Chicago field office for ICE exceeded the government’s authority to detain immigrants without a warrant.

Los Angeles doesn’t turn over people arrested for low-level crimes to ICE. Philadelphia won’t cooperate with detainer requests unless the person has committed a first- or second-degree felony involving violence. Providence continues holding only individuals subject to a criminal detainer, meaning they were convicted of a prior crime, typically a felony.

Sanctuary polices don’t deter federal agents from conducting operations to find undocumented immigrants. Federal agents routinely identify child molesters, gang members and other criminals for removal even in sanctuary cities by going into communities, thanks to their own intelligence-gathering.

Some localities actively partner with ICE, and some have aggressively pursued undocumented immigrants through their own programs. In Arizona, Maricopa County Sheriff Joe Arpaio faces a criminal contempt-of-court charge for defying a judge’s order to stop conducting immigration patrols. His lawyer has said he will fight the charge. The sheriff lost a re-election bid last week.

More than 2.5 million people have been deported by the Obama administration. It has prioritized the removal of convicted criminals and recent illegal border crossers, which isn’t dissimilar to what president-elect Trump suggested would be his administration’s emphasis in a recent interview on CBS’ “60 Minutes.”

Republicans have criticized noncompliant jurisdictions. The Republican-controlled House of Representatives passed legislation last year that would withhold federal, law-enforcement grants from cities that shelter undocumented immigrants. President Barack Obama said he would veto the bill and Senate Democrats blocked a version in that house.

The term “sanctuary city” is ill-defined, said Los Angeles Mayor Eric Garcetti, a Democrat.

“We would not like to lose federal funds,” Los Angeles Police Chief Charlie Beck said Tuesday. “But I will tell you this: Whether or not I do the right thing is not a matter of money. This is a matter of principle.”

Click for more from The Wall Street Journal