You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is because object does not allow accessing any custom properties, so effectively there are only a couple of properties that you can access when using this with Typescript. By using generics, developers are allowed to shape that property as they probably now the actual model of data property. By using defaults, if the developer does not provide a type, then data will be any, allowing to access any custom property.
The text was updated successfully, but these errors were encountered:
In 4.0.2 we have used the type { [key: string]: any; } because without validation that the parsed frontmatter matches the type T, it is probably not a good idea to just cast the read-in type to T. It's just going to result in unexpected errors.
You can add a validation + typecast logic on top of that type if you like.
At any rate, I'm going to close this as "won't fix". Cheers.
I originally posted this in #67, but I realize that this is actually a bug when using Typescript.
I would like to type the
data
property inGrayMatterFile
interface. With a generic type, of curse. Could be done with this:Using default generics again, allow this to keep backward compatibility, if the
T
is declared after theI
.This is because
object
does not allow accessing any custom properties, so effectively there are only a couple of properties that you can access when using this with Typescript. By using generics, developers are allowed to shape that property as they probably now the actual model ofdata
property. By using defaults, if the developer does not provide a type, thendata
will beany
, allowing to access any custom property.The text was updated successfully, but these errors were encountered: