Grid-tied inverters which only deliver active power to the mains in the sine wave current way are simple to control. However, they cannot improve and control the power quality of the mains. This paper proposes a new kind of grid-tied inverter based on the instantaneous reactive power theory and harmonic detection algorithm. Besides the transmission of normal active current, the new grid-tied inverter can inject appropriate reactive and harmonic currents into the mains according to the quality of the mains. Consequently, the reactive power and harmonic current in the mains can be compensated. Control strategies and harmonic signal detection methods are derived for different operation modes such as the active power transmission mode, the reactive power compensation mode, and the harmonic current filtering mode. Detailed simulation results have verified the validity of the proposed methodology.