Monday, September 06, 2021

TypeScript 4.4: "catch uknown"

many new linter errors with TypeScript upgrade... 
"solution": catch (err: any)

Announcing T TypeScript 4.4 |ypeScript

In JavaScript, any type of value can be thrown with throw and caught in a catch clause. Because of this, TypeScript historically typed catch clause variables as any, and would not allow any other type annotation:

That’s why TypeScript 4.4 introduces a new flag called --useUnknownInCatchVariables. This flag changes the default type of catch clause variables from any to unknown.

try {
    executeSomeThirdPartyCode();
}
catch (err) { // err: unknown (default type, used to be "any")

    // Error! Property 'message' does not exist on type 'unknown'.
    console.error(err.message);

    // Works! We can narrow 'err' from 'unknown' to 'Error'.
    if (err instanceof Error) {
        console.error(err.message);
    }
}

Geekout: Renewable Energy

It is recorded over SpaceX StarLink satellite internet!
Apparently StarLink is quite usable already!

Geekout: Renewable Energy - Talk Python Live Stream Episode 329 - YouTube


Episode #329 Geekout: Renewable Energy - [Talk Python To Me Podcast]


Links from the show

Richard on Twitter: @richcampbell

IEA report 2021: iea.org
Flywheel storage: blogspot.com
Crane storage: eni.com
Pumped hydro storage: eurekalert.org
Tesla battery utility-scale: tesla.com
The US’s largest solar farm is canceled because Nevada locals don’t want to look at it: electrek.co
DEVintersection conference (run by Richard): devintersection.com
.NET Rocks Podcast (Richard's a cohost, many geekout episodes): dotnetrocks.com

Prior Geekouts on Talk Python
#276: Geekout: Life in the solar system and beyond: talkpython.fm
#253: Moon base geekout: talkpython.fm
Episode transcripts: talkpython.fm