#Define an interface for interfaces
45 messages · Page 1 of 1 (latest)
@fleet dock I think mostly "no".
actually managed to do that but facing rn an different issues
Did you do this?
interface IndexSignature {
[key: string]: { content: unknown }
}
interface SpecificInterface extends IndexSignature {
foo: { content: "foo"}
test: 0
}
This is why I said "mostly" - but I don't think this is a good idea.
OMG
In the exact second
I fixed the different issue
which was caused by this
LMAO
so besides this there is no way?
I don't think so. I guess this is okay if you're using --noUncheckedIndexedAccess.
nah its causing other issues
I have in some places keyof
and if i create a type extending that to check the schema
it will allow for any key
Yup, that's what the index signature does.
interface SpecificInterface extends IndexSignature {
foo: { content: "foo"}
}
declare const x: SpecificInterface;
const y = x.bar; // compiles
Though if you turn on noUncheckedIndexedAccess then at least x.bar will be { content: unknown } | undefined.
nah i bite the bullet
i just prepare a template to copy
I am creating an modular event system where people can define value types etc
so i wanted to write a small support
but its not worth it if it causes these issues
Deleting it in a short bit
the last thing i need to figure out is that if the type of extensionData is not an empty object that it then is required, otherwise optional
If you use types, they can be assignable to an index signature without needing to incldue it explicitly:
interface IndexSignature {
[key: string]: { content: unknown }
}
let i: IndexSignature;
type Type1 = {
foo: { content: "foo"}
}
declare const x1: Type1;
i = x1; // compiles
type Type2 = {
foo: { content: "foo"},
bar: 0
}
declare const x2: Type2;
i = x2;
//
// Type 'Type2' is not assignable to type 'IndexSignature'.
// Property 'bar' is incompatible with index signature.
// Type 'number' is not assignable to type '{ content: unknown; }'.
@glacial trench issue is that here im moving purely in types, no const let etc
the type extension is to allow to define the types of the event system easier
it has no actual effect
Yeah, I don't think there's a way to enforce constraints on types that are defined.
Except maybe generics, I guess?
I don't think I have enough context on what you're trying to do, honestly.
i am creating an event system for a website builder
so you can hook into the editor ui
and check if the editor creates an element
and then for example trigger custom plugin events
for some reason this omits all other propeties besides extensionData
wreid
solved
!solved