Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interface support (Typescript) #2

Closed
Pilaton opened this issue Apr 12, 2024 · 1 comment
Closed

Add interface support (Typescript) #2

Pilaton opened this issue Apr 12, 2024 · 1 comment

Comments

@Pilaton
Copy link

Pilaton commented Apr 12, 2024

Currently, typing is only supported using "type" and not "interface".

Example for reproducing an error:

interface IData {
  title: string;
};

const { frontmatter } = await evaluate<IData>({...});

Error:

Type 'IData' does not satisfy the constraint 'Record<string, unknown>'. 
@Pilaton Pilaton closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2024
@talatkuyuk
Copy link

talatkuyuk commented Apr 20, 2024

The type parameters TFrontmatter and TScope (in your case IData) should extend Record<string, unknown>.

The reason you got error is that the types declared with interface are a possible target for declaration merging, so their properties are not fully known. This is not the case for type aliases.

That is why you should use type instead of interface:

type IData = {
  title: string;
};

You can find additional information from here and here.

Hope it solves your issue. By the way, @Pilaton, I liked your portfolio and gave a star for the project sleep-sleep which is well structured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants