Skip to content

Fix incorrect type-declaration#77

Open
neurolag wants to merge 3 commits intojxson:masterfrom
neurolag:master
Open

Fix incorrect type-declaration#77
neurolag wants to merge 3 commits intojxson:masterfrom
neurolag:master

Conversation

@neurolag
Copy link

@neurolag neurolag commented Oct 5, 2020

General

The front-matter module uses the module.exports = fm-pattern to expose the library.
Currently the type-declaration doesn't represent this correctly and instead asserts an export default fm.

This contradicts with each other and causes typescript to not work correctly.

This PR fixes the type-declarations accordingly.

The Solution

The solution is to move every existing component (such as FrontMatterOptions, FM etc.) into a namespace which merges with the fm-function:

front-matter/index.d.ts

Lines 1 to 23 in d367565

declare namespace fm {
export interface FrontMatterResult<T> {
readonly attributes: T
readonly body: string
readonly bodyBegin: number;
readonly frontmatter?: string
}
export interface FrontMatterOptions {
/**
* Whether to use [safeload](https://github.com/nodeca/js-yaml#safeload-string---options-)
* @default true
*/
allowUnsafe?: boolean
}
export interface FrontMatter {
<T>(file: string, options?: FrontMatterOptions): FrontMatterResult<T>
test(file: string): boolean
}
}
declare const fm: fm.FrontMatter;

Afterwards the fm-function can be exported the same way it is exported in the actual source-file (which is using an export = fm-expression):

export = fm;

Merging this PR fixes issue #76

@karlhorky
Copy link

@jxson @peterbe @tyankatsu0105 what do you think about this PR?

It looks like the current TypeScript types are broken:

Screenshot 2024-07-11 at 10 09 30

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

Successfully merging this pull request may close these issues.

2 participants