question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Typescript Decoration File

See original GitHub issue

Using 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
florianbepunktcommented, Jan 14, 2020

@claudiosanches Could this commit please be pushed to npm as well?

0reactions
joeyorlandocommented, May 16, 2020

still unable to use Typescript declaration file, v1.0.1 pulled from npm doesn’t include it 😞

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found