# Results of ArgMax as a function of a parameter with InterpolatingFunctions

I would like to obtain a function and its derivatives, where the function is defined as the solution to a maximization problem. The obvious approach

Clear[f]
f[a_?NumericQ] := NArgMax[-(x - a)^2, x]
f[1]
f'[1]


fails to give the numeric f'[1]. So I used the following:

Clear[f]
f = FunctionInterpolation[ArgMax[-(x - a)^2, x], {a, 0, 2}]
f'[1]


The actual function I would like to maximize has no closed form, thus an InterpolatingFunction object must be used:

Clear[f, g]
g = FunctionInterpolation[-(x - a)^2, {x, 0, 2}, {a, 0, 2}];
f = FunctionInterpolation[ArgMax[g[x, a], x], {a, 0, 2}]
f'[1]


This gives the error

FunctionInterpolation::nreal: Near {a} = {0}, the function did not evaluate to a real number.

How to avoid this error and get the correct f'[a] for any a?

Clear[f, g, gg]