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 type definition file #211

Merged
merged 3 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.0.0",
"description": "Autoload Config for PostCSS",
"main": "src/index.js",
"types": "types/index.d.ts",
"files": [
"src"
],
Expand Down
44 changes: 44 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Type definitions for postcss-load-config 2.1
ai marked this conversation as resolved.
Show resolved Hide resolved
import Processor from 'postcss/lib/processor'
import { Plugin, ProcessOptions, Transformer } from "postcss";
import { Options as CosmiconfigOptions } from 'cosmiconfig';

// In the ConfigContext, these three options can be instances of the
// appropriate class, or strings. If they are strings, postcss-load-config will
// require() them and pass the instances along.
interface ProcessOptionsPreload {
parser?: string | ProcessOptions['parser'];
stringifier?: string | ProcessOptions['stringifier'];
syntax?: string | ProcessOptions['syntax'];
}

// The remaining ProcessOptions, sans the three above.
type RemainingProcessOptions =
Pick<ProcessOptions, Exclude<keyof ProcessOptions, keyof ProcessOptionsPreload>>;

// Additional context options that postcss-load-config understands.
interface Context {
cwd?: string;
env?: string;
}

// The full shape of the ConfigContext.
type ConfigContext = Context & ProcessOptionsPreload & RemainingProcessOptions;

// Result of postcssrc is a Promise containing the filename plus the options
// and plugins that are ready to pass on to postcss.
type ResultPlugin = Plugin | Transformer | Processor;

interface Result {
file: string;
options: ProcessOptions;
plugins: ResultPlugin[];
}

declare function postcssrc(ctx?: ConfigContext, path?: string, options?: CosmiconfigOptions): Promise<Result>;

declare namespace postcssrc {
function sync(ctx?: ConfigContext, path?: string, options?: CosmiconfigOptions): Result;
}

export = postcssrc;