noun
note left by a dead person; suicide note; testamentary letter; will
A written message left in anticipation of death or found after death, often a suicide note or final instructions. For a formal legal will, 遺言書 is often the more precise word, but 遺書 can overlap with testamentary writing.
机の上に遺書が残されていた。
A note from the deceased had been left on the desk.
彼女は家族への遺書に感謝の言葉を書いた。
She wrote words of thanks to her family in her final letter.
noun
posthumous work; writings left behind
Less common, literary or scholarly use for writings or a work left behind by someone after death. In ordinary modern Japanese, 遺著 is often clearer for a posthumous work.
文学の文脈では、遺書が死後に残された著作を指すこともある。
In a literary context, 遺書 can refer to a work left behind after someone's death.
Specifically a posthumous work or writings left by an author; clearer than the rare posthumous-work sense of 遺書.
A Sino-Japanese compound: 遺 means something left behind or bequeathed, and 書 means writing or document. The spelling is transparently associated with a written thing left after death.