Single-space chapter titles with double-spaced document

You could add the following instructions to the document's preamble (after loading the setspace package):

\usepackage{sectsty}
\allsectionsfont{\singlespacing}

A full MWE (minimum working example):

\documentclass[12pt,oneside]{book}
\usepackage{lipsum}   % for filler text
\usepackage{setspace} 
\doublespacing

\usepackage{sectsty}
\allsectionsfont{\singlespacing}

\begin{document}

\chapter{I need singlespace titles, doublespace text.}

\section{Section headers should also be single-spaced, but I could adjust titles to fit on one line}

\lipsum[4] % filler text
\end{document}

A related question has a solution for section headings using the titlesec package. However, if this answer is copied and naïvely modified for chapter headings, it will result in a ! Package titlesec Error: Not allowed in 'easy' settings error. The error arises because the titlesec package works a little differently with chapters than it does sections. An incantation to single-space chapters and section headers using the titlesec package is as follows:

\usepackage{titlesec}
\titleformat{\chapter}[display]{\normalfont\huge\bfseries\singlespacing}{\chaptertitlename\ \thechapter}{40pt}{\huge}
\titleformat{\section}{\singlespacing\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\singlespacing\normalfont\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}{\singlespacing\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}