If a phase transition is allowed to take place in the core of a compact star, a new stable branch of equilibrium configurations can appear, providing solutions with the same mass as the purely hadronic branch and hence giving rise to "twin-star" configurations. We perform an extensive analysis of the features of the phase transition leading to twin-star configurations and, at the same time, fulfilling the constraints coming from the maximum mass of 2 M and the information following gravitational-wave event GW170817. In particular, we use a general equation of state for the neutron-star matter that parametrizes the hadron-quark phase transition between the model describing the hadronic phase and a constant speed of sound for the quark phase. We find that the largest number of twin-star solutions has masses in the neutron-star branch that are in the range 1-2 M and maximum masses 2 M in the twin-star branch. The analysis of the masses, radii and tidal deformabilities also reveals that when twin stars appear, the tidal deformability shows two distinct branches with the same mass, thus differing considerably from the behaviour expected for normal neutron stars. In addition, we find that the data from GW170817 is compatible with the existence of hybrid stars and could also be interpreted as produced by the merger of a binary system of hybrid stars or of a hybrid star with a neutron star. Indeed, with the use of a well-established hadronic EOS the presence of a hybrid star in the inspiral phase could be revealed if future gravitational-wave detections measure chirp masses M 1.2 M and tidal deformabilities of Λ1.4 400 for 1.4 M stars. Finally, combining all observational information available so far, we set constraints on the parameters that characterise the phase transition, the maximum masses, and the radii of 1.4 M stars described by equations of state leading to twin-star configurations.