Tim (Miles Christopher Bakshi) deals with  the new presence of an officious infant brother (Alec Baldwin) in “The Boss Baby.” (DreamWorks Animation via Associated Press)

TOM McGRATH has worked with a handful of veteran comic talents, including Will Ferrell and Tina Fey, who have impersonated political figures on SNL. But back when he cast Alec Baldwin for his newest CGI-animated film, “The Boss Baby,” the director had no idea that Baldwin’s Trump impression would now be in full bloom on “Saturday Night Live.”

That timing is fortuitous, McGrath tells The Post’s Comic Riffs in a recent interview in Washington, as the heat of Baldwin’s current spotlight has only raised the curiosity factor around another role in which Baldwin plays the new boss.

The actor’s distinctive comic voice is central to the DreamWorks-animated “The Boss Baby,” which opened to $49 million in its domestic debut, according to studio estimates Sunday, outpacing projections as well as the Disney powerhouse “Beauty and the Beast” ($48 million). Final numbers are due Monday.

Topping “Beauty” would be no small feat; Disney’s live-action adaptation has grossed nearly $400 million domestically in less than a month.

“Boss Baby’s” success underscores the audience appetite for family-friendly animation even before the summer season, regardless of reviews. The Fox-distributed film has an average score of just 50 on MetaCritic.com, and a rating of 49 percent fresh on Rotten Tomatoes.

McGrath, who directed “Megamind” and three “Madagascar” films, worked with writer Michael McCullers (“Baby Mama,” “Austin Powers” films) to adapt the 2010 children’s book by Caldecott-winning writer-artist Marla Frazee.

Both the book and film center on how a 7-year-old boy (voiced by Miles Christopher Bakshi) reacts when an officious baby brother enters the picture so needy that he seems to be bossing around the parents.

Producer Ramsey Ann Naito, a veteran of the Maryland Institute College of Art, tells Comic Riffs during a recent Washington visit that she immediately related to the book, particularly because she remembered the jealousy exhibited by her then-7-year-old son when her second son arrived. Naito took the book to McGrath, a longtime friend, who says the story resonated with him because of his childhood relationship with an elder brother. The project soon took shape, adding Steve Buscemi, Jimmy Kimmel, Lisa Kudrow and Tobey Maguire to the voice cast.

“Boss Baby” might not have the pathos of a Pixar movie or the sheer beauty of a Studio Ghibli film. But the new movie, which has grossed $70.2 million worldwide, is amiable, action-heavy and stylish in its nods to vintage Looney Tunes art.

So while the headline-grabbing Paramount remake “Ghost in the Shell” ($19 million) tanked in its domestic debut this weekend, “Boss Baby” is the little engine that — powered by former “Thomas the Tank Engine” narrator Alec Baldwin — could find a second-weekend audience.