Typescript error with required properties
See original GitHub issueIt seems like AllowImplicit
is confusing Typescript into thinking that required properties are optional.
interface A {
a: string;
}
const aDecoder: Decoder<A> = object({
a: string
});
Output:
Type 'Decoder<{ a?: string; }, unknown>' is not assignable to type 'Decoder<A, unknown>'.
Type '{ a?: string; }' is not assignable to type 'A'.
Property 'a' is optional in type '{ a?: string; }' but required in type 'A'.ts(2322)
Live example: https://codesandbox.io/s/nostalgic-sinoussi-lkrq1?file=/src/index.ts
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
node.js - Typescript error when adding property to Error object ...
TypeScript does not allow adding unknown properties. There are ways to define objects with arbitrary keys (e.g. Record ).
Read more >required properties produce a typescript error #2936 - GitHub
I was able to fix this issue by creating a new tscsonfig file in my entities folder, which includes "strictPropertyInitialization": false .
Read more >Error - JavaScript - MDN Web Docs - Mozilla
Error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions.
Read more >Handbook - Interfaces - TypeScript
Not all properties of an interface may be required. Some exist under certain conditions or ... Error: Property 'clor' does not exist on...
Read more >React+TypeScript: 'missing required attribute' error reported ...
React+TypeScript: 'missing required attribute' error reported for required properties passed in by redux `connect` ... I would expect this to work. However ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I narrowed it down to the
strict
setting intsconfig.json
."strict": false
(the default, when not set), the problem exists"strict": true
the problem is goneSteps to reproduce
Step 1: Create npm project
Step 2: Create source file
Create file
repro.ts
:Step 3: Create tsconfig.json files
Create
tsconfig.bad.json
:Create
tsconfig.ok.json
:Step 4: Demonstrate behaviour
Demostrate different behaviour:
See difference in config:
Thanks!!