There are basically two types of Irvine Welsh novel. There are the deeply felt and vividly evoked stories about young men going to the bad on the mean streets of Leith (Trainspotting, Glue). Then there are his silly, sick ones, whether the genre is tapeworm-infested police procedural (Filth), evil-double gothic (The Bedroom Secrets of The Master Chefs) or psychedelic thalidomide revenge fantasy (Ecstasy).

This is a simplification: the desire to shock runs deep in Welsh, and all his books are at least slightly sick and sensationalistic. But when it comes down to brass tacks, Welsh has one great story to tell; and much of the rest of his career has been spent failing to find another one in ever more desperate and revolting ways, apparently feeling that he's letting the side down if there isn't a haemorrhoid-scratching scene or a ruptured penis or child being dismembered every few pages.

I was really looking forward to Skagboys, which falls clearly into the first category. The prequel to Trainspotting, it is billed – like most of his novels – as his best since then. It begins in 1984, and it follows Renton, Sick Boy and Spud as they become heroin addicts, and Begbie as he graduates from Leith bully to fully-fledged Edinburgh-wide psycho. The prologue, in which Renton joins his father's union on the picket line at the Battle of Orgreave during the miners' strike, sees Welsh at his sweary, eloquent best. It kicks off in convoluted standard English before liberating itself into broad housing scheme Scots. Renton is beaten up by the police, and left with back pain and a sense that there's no future: "Ah'm thinkin that we've lost, and there's bleak times ahead, and ah'm wonderin: what the fuck am ah gauny dae wi the rest ay ma life?"

At this point, the book seems to be shaping up as a blunt but powerful anti-Thatcherite epic. Spud is laid off from his job as a removals man. Renton finds himself doing de-skilled carpentry work for "the kind ay small businessman Thatcher loves; a grasping, spiritually dead, scab-minded cunt". There are mini-essays about the Tories' failure to devolve power to Scotland, and about the spread of HIV in Edinburgh; there are sub-plots set in the pharmaceutical factory from which high-grade heroin is flooding on to the streets. But ultimately, it's a more confused and personal book than that.

Renton has all the chances – a place at university, a lovely girlfriend – but blows them all, owing, it seems, to his torment over his "spazzy" younger brother, and to something like an identity crisis: "That's ma problem; ah'm too fuckin poncy tae be a proper Leith gadgie n too fuckin schemie tae be an arty student type." In the end, the blame for the gang's wasted lives is shared between Thatcher, class, screwed-up families and something else: original sin, maybe.

Coming back to Trainspotting nearly 20 years after it was published, it still seems like one of the more interesting British novels of recent decades. It's a sort of hellish social comedy, in which a whole subculture is artfully compressed into 44 fragmented chapters. You sense that Welsh knows the terrain like the back of his hand; that he knows where every minor character went to school, and how they got their nickname. Along with a great ear for dialogue and local detail, Welsh has a powerful wider political story to tell: how the country's industrial communities were hollowed out in the 1980s ("the substitution of drugs for jobs in the poorest parts of Britain", as he has put it). But he tells it in an exhilarating style that makes the traditional social realist model for such stories – think of Ken Loach or early James Kelman – look earnest and plodding.

Perhaps Welsh was able to do all this because he had in fact written an entire unpublished novel's worth of background. When the sequel, Porno, came out 10 years ago, he said that he had written "a huge amount more of Trainspotting than went into the book, but I didn't want to rehash that". Well, now he's done exactly that, and the result is Skagboys. Presumably this is why it reads like somebody's interesting but confused first novel: nakedly autobiographical, stylistically uneven, with some fascinating passages and a fair amount of earnest and plodding social realism. Welsh appears literally to be finding his voice, ranging from student-pretentious ("the lines from that classic Dylan Thomas poem resonated in her") to Penguin Classic ("Ronnie turned to George, estimating that his younger brother was more likely to be a peer of this boy who had disgraced their sister"). Only in some sections does he hit the confident, precise tone of Trainspotting, in which casually deployed official English collides with the vernacular: "You can operate fae the purest of motives but some fuckers will eywis misconstrue it to fit their ain twisted agenda."

Skagboys is also just too long: it essentially goes over the same ground as Trainspotting, yet it's about three times the size. There is the same run of highs and lows, skag hits and funerals. Sick Boy shags and mistreats his way through the book, while Begbie batters and stomps and chibs. There are even reruns of famous passages from the previous novel, including a minor-key reprise of Renton's "choose life" rant about how he doesn't want a nine-to-five and a mortgage. The bits that deviate from the old routines often seem the most uncertain. There's a slack, meandering section set in a Hackney squat. And Renton's happy student days are a little insipid – he even goes InterRailing!

For all that, there are many unforgettable episodes, such as the visit to a squalid shooting gallery, where one large hospital syringe passes round the room from junky to junky, like the angel of death. Even at his weakest, Welsh performs the mysterious feat of making you think that his characters are real. But by the time, a few pages from the end, that Renton is heard saying: "it's no like some famous cunt's gaunny come along and make a film ay our lives, is it?", the reader has a vivid sense of a great talent tamely revisiting his glory days.