type-fest
type-fest copied to clipboard
SetRequired unable to infer type
export interface ModelEntity<ID extends string | number | unknown> extends Identifiable<ID> {
readonly createdAt: ZonedDateTime;
modifiedAt: ZonedDateTime;
}
export interface AggregateRoot<ID extends string | number | unknown, STATUS>
extends ModelEntity<ID> {
readonly status: STATUS;
}
export type AggregateOptsExcept<T extends AggregateRoot<unknown, unknown>> = Except<
T,
'id' | 'createdAt' | 'modifiedAt'
>;
type PartialAggregateOpts<T extends AggregateRoot<unknown, unknown>> = Partial<
AggregateOptsExcept<T>
>;
export type AggregateOpts<T extends AggregateRoot<unknown, unknown>> = SetRequired<
PartialAggregateOpts<T>, 'status' // compile error here, it doesn't recognize status
>;
app-lib/graph/packages/app/src/shared/model.ts:59:3 - error TS2344: Type 'string' does not satisfy the constraint 'Exclude<keyof T, "id" | "createdAt" | "modifiedAt">'.
59 'status'
~~~~~~~~
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- The funding will be given to active contributors.
- Thank you in advance for helping prioritize & fund our backlog.
What TypeScript version are you using? Did you try the latest one?
// @crhistianramirez
looks like not quite the latest
> yarn info typescript # services -> feature/RS2-1286 $ — ! ? RC=141
└─ typescript@patch:typescript@npm%3A4.0.2#builtin<compat/typescript>::version=4.0.2&hash=5bf698
├─ Version: 4.0.2
│
└─ Exported Binaries
├─ tsc
└─ tsserver
@xenoterracide Hello! Please make an effort to create a minimal reproducible example in the future.
I did it for you: TS Playground
By the way, interestingly, the compiler error message changes (for worse, IMO) from TS 3.9 to TS 4.0. You can quickly see this by changing the version in the playground.
@xenoterracide Hello! Please make an effort to create a minimal reproducible example in the future.
sorry about that, I'd hoped my pasted code would be enough.