-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
The docs say that traits can be typed with a generic parameter:
Lines 711 to 727 in 52a79cb
| Traits can have a schema type passed into its generic. This can be useful if the inferred type is not good enough. | |
| ```ts | |
| type AttackerSchema = { | |
| continueCombo: boolean | null | |
| currentStageIndex: number | null | |
| stages: Array<AttackStage> | null | |
| startedAt: number | null | |
| } | |
| const Attacker = trait<AttackerSchema>({ | |
| continueCombo: null, | |
| currentStageIndex: null, | |
| stages: null, | |
| startedAt: null, | |
| }) | |
| ``` |
However, this seems to be broken (v0.5.3)1:
import { trait } from "koota";
type MySchema = {
foo: number;
bar: string;
baz: [number, string];
};
const MyTrait = trait<MySchema>({
// ~~~~~~~~ Type 'MySchema' is not assignable to type 'Record<string, never>'
foo: 0,
bar: "",
baz: () => [0, ""],
});satisfies can't be used as a workaround in this case either, due to objects requiring initializer functions:
const MyTrait = trait({
foo: 0,
bar: "",
baz: () => [0, ""],
// ~~~ Type '() => (string | number)[]' is not assignable to type '[number, string]'
} satisfies MySchema);Footnotes
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels