'Type 'string | number | symbol' is not assignable to type 'string'
I have a error with following type definition, at L102.
TypeScript 4.6.2 sais...
(property) Schema.items?: Schema | undefined
Type 'Schema & p["items"]' does not satisfy the constraint 'Schema'.
Types of property 'required' are incompatible.
Type '(readonly (keyof NonNullable<(Schema & p["items"])["properties"]>)[] & readonly (keyof NonNullable<p["items"]["properties"]>)[]) | undefined' is not assignable to type 'readonly string[] | undefined'.
Type 'readonly (keyof NonNullable<(Schema & p["items"])["properties"]>)[] & readonly (keyof NonNullable<p["items"]["properties"]>)[]' is not assignable to type 'readonly string[] | undefined'.
Type 'readonly (keyof NonNullable<(Schema & p["items"])["properties"]>)[] & readonly (keyof NonNullable<p["items"]["properties"]>)[]' is not assignable to type 'readonly string[]'.
The types returned by 'concat(...)' are incompatible between these types.
Type '(keyof NonNullable<(Schema & p["items"])["properties"]>)[]' is not assignable to type 'string[]'.
Type 'keyof NonNullable<(Schema & p["items"])["properties"]>' is not assignable to type 'string'.
Type 'string | number | symbol' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.(2344)
If I change L34, Schema interface definition, from
readonly required?: ReadonlyArray<keyof NonNullable<this['properties']>>;
to
readonly required?: ReadonlyArray<keyof NonNullable<Schema['properties']>>;
that removes the error, but I want to use this.
Is there any way to clear errors while using this?
Solution 1:[1]
Use Extract.
readonly required?: ReadonlyArray<Extract<keyof NonNullable<this['properties']>, string>>;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tamaina |
