Disclosed are a heterocyclic derivative as a JAK inhibitor, and salts thereof, wherein the definitions of (II), (III) and R are described in detail in the specification. In addition, also disclosed are a medicine comprising the compound and salts thereof as an active ingredient, and the use thereof in the preparation of a medicine for treating JAK-related target diseases, such as immune system diseases, rheumatoid arthritis and tumors. Ⓐ (II) Ⓑ (III)