def encode(s: str) -> str:
    """
    Turns all astral characters (code points U+10000 and bigger)
    in string ``s`` into surrogate pairs:
    a high surrogate (code points U+D800 to U+DBFF)
    followed by a low surrogate (code points U+DC00 to U+DFFF).
    """
    if not isinstance(s, str):
        raise TypeError('Not a string: {!r}'.format(s))

    encoded_s = []

    for ch in s:
        if ord(ch) < 0x10000:
            encoded_s.append(ch)
        else:
            high_surrogate = ((ord(ch) - 0x10000) // 0x400) + 0xD800
            low_surrogate = ((ord(ch) - 0x10000) & (0x400 - 1)) + 0xDC00
            encoded_s.append(chr(high_surrogate) + chr(low_surrogate))

    return ''.join(encoded_s)