[Feature Request] Typescript Decoration File
See original GitHub issueUsing Typescript to enforce type checking in JavaScript project is the normal behavior nowadays. Providing a Typescript Decoration file for the people who use this official API lib is important for the programmers.
I have written a template decoration file for my own project and you may take it as a reference. Some part may not be correct.
declare module '@woocommerce/woocommerce-rest-api' {
export type WooCommerceRestApiVersion = 'wc/v3' | 'wc/v2' | 'wc/v1' | 'wc-api/v3' | 'wc-api/v2' | 'wc-api/v1'
export type WooCommerceRestApiEncoding = 'utf-8' | 'ascii'
export type WooCommerceRestApiMethod = 'get' | 'post' | 'put' | 'delete' | 'options'
export interface IWooCommerceRestApiOptions {
url: string
consumerKey: string
consumerSecret: string
wpAPIPrefix?: string
version?: WooCommerceRestApiVersion
encoding?: WooCommerceRestApiEncoding
queryStringAuth?: boolean
port?: number
timeout?: number
axiosConfig?: any
}
export interface IWooCommerceRestApiQuery {
[key: string]: string
}
class OAuth {}
export class WooCommerceRestApi {
protected classVersion: string
protected url: string
protected consumerKey: string
protected consumerSecret: string
protected wpAPIPrefix: string
protected version: WooCommerceRestApiVersion
protected encoding: WooCommerceRestApiEncoding
protected queryStringAuth: boolean
protected port: number
protected timeout: number
protected axiosConfig: any
constructor(opt: IWooCommerceRestApiOptions | WooCommerceRestApi)
private _setDefaultsOptions(opt: IWooCommerceRestApiOptions): void
private _parseParamsObject(params: any, query: any): IWooCommerceRestApiQuery
private _normalizeQueryString(url: string, params: any): string
private _getUrl(endpoint: string, params: any): string
private _getOAuth(): OAuth
private _request(method: WooCommerceRestApiMethod, endpoint: string, data: any, params: any): any
public get(endpoint: string): any
public get(endpoint: string, params: any): any
public post(endpoint: string, data: any): any
public post(endpoint: string, data: any, params: any): any
public put(endpoint: string, data: any): any
public put(endpoint: string, data: any, params: any): any
public delete(endpoint: string): any
public delete(endpoint: string, params: any): any
public options(endpoint: string): any
public options(endpoint: string, params: any): any
}
export class OptionsException {
public name: string
public message: string
constructor(message: string)
}
export default WooCommerceRestApi
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Documentation - Decorators - TypeScript
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use...
Read more >A practical guide to TypeScript decorators - LogRocket Blog
In a nutshell, a decorator is a pattern in programming in which you wrap something to change its behavior. In JavaScript, this feature...
Read more >TypeScript configuration - Angular
It is a superset of JavaScript with design-time support for type safety and ... A given Angular workspace contains several TypeScript configuration files....
Read more >node.js - Extend Express Request object using Typescript
You want to create a custom definition, and use a feature in Typescript called Declaration Merging. This is commonly used, ...
Read more >Announcing TypeScript 4.7 - Microsoft Developer Blogs
directives; however, we received some feedback on import type and wanted to reconsider the needs and design of the feature.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@claudiosanches Could this commit please be pushed to npm as well?
still unable to use Typescript declaration file, v1.0.1 pulled from npm doesn’t include it 😞