Altinn / app-frontend-react

Altinn application React frontend
BSD 3-Clause "New" or "Revised" License
14 stars 24 forks source link

Fix hierarchy generation crashing due to missing null check #2056

Closed bjosttveit closed 3 weeks ago

bjosttveit commented 3 weeks ago

Description

The Javascript type system is amazing as always, this error was due to the fact that typeof null === 'object' returns true, combined with the fact that any in Typescript does not do type-narrowing very well. Switching any to unknown made the mistake more apparent, now warning that obj could be either object | null which gave a type error in Object.keys.

A lesson here is that unknown can be more useful in cases like this instead of using any explicitly when you dont know the type.

Related Issue(s)

Verification/QA

sonarcloud[bot] commented 3 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud