The difference between local and play environment is strictNullChecks
. It's set to false by default locally, but is enabled on the playground by default.
Here is the playground link with strictNullChecks
set to false.
The fix was as simple as changing preview = undefined
to preview = unknown
. Which I could have sworn I tried and it didn't work but here we are 🤷♂️
Here is an insightful explanation by @andrewbranch
The way --strictNullChecks=false works is we remove undefined | null from the domain of every type by the time you observe it. So string | null | undefined becomes string. So what does undefined become when you remove undefined from its domain?
It becomes the empty union, aka never!
Test case for a weird problem with TypeScript.
Here is the playground link where the problem does not occur.
But to reproduce the problem locally:
git clone [email protected]:09182ddd46e72672a8a8a30e34942988.git gist-typescript-test
cd gist-typescript-test
npm install
npx tsc --noEmit --declaration --noUnusedLocals test.ts
Results in
test.ts:72:14 - error TS2322: Type '{}' is not assignable to type 'never'.
72 export const getApp: GetApp = {};
~~~~~~
Found 1 error.
For me, anyway.
When changing
-export const getApp: GetApp = {};
+export const getApp: GetApp = {
+ mediaType: {
+ previews: [],
+ },
+};
The error is
test.ts:74:5 - error TS2322: Type 'undefined[]' is not assignable to type 'never'.
74 previews: [],
~~~~~~~~
🤷♂️ halp