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.

Consider adding a TypeScript definitions file

See original GitHub issue

I’m using https://github.com/mgechev/angular2-seed for my angular2 app and I want to include wordpress-rest-api in a component file (typescript) but it’s not working.

import * as WP from 'wordpress-rest-api/wp'; gave the error can't find module

I also tried require( 'wordpress-rest-api/wp' ) gave the error Unhandled rejection Error: Error on fetch for node.extend.js

export class AppCmp {
  constructor(){
    var WP = require( 'wordpress-rest-api/wp' );
    var wp = new WP({ endpoint: 'http://localhost/murhaf/wp-json' });

    wp.posts().then(function(data){
        console.log(data);
      }).catch(function( err ) {
        console.log(err);
    });
}

Thanks.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:24

github_iconTop GitHub Comments

2reactions
johnbillioncommented, May 17, 2020

I recently created a package that provides TypeScript definitions for the JSON representation of WordPress core PHP objects (WP_Error, WP_Post, and WP_User for now): https://github.com/johnbillion/wp-types . I’d like to extend this to include the same for core objects in REST API responses, so if anyone’s interested in getting involved I’d appreciate it!

1reaction
thefrostycommented, Jun 16, 2021

These can be used to put a base for all types, then extend and maintain the types. https://github.com/Microsoft/dts-gen https://github.com/DefinitelyTyped/DefinitelyTyped/

⇒  dts-gen -m wpapi -d wpapi     
⇒  ls types/wpapi 
index.d.ts  tsconfig.json  tslint.json  wpapi-tests.ts

I came across this: https://www.npmjs.com/package/@types/wpapi

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Type Declarations
TypeScript automatically finds type definitions under node_modules/@types , so there's no other step needed to get these types available in your program.
Read more >
A quick introduction to “Type Declaration” files and adding ...
In this lesson, we are going to take a closer look at type declaration files which are one of the key ingredients of...
Read more >
TypeScript: Adding Custom Type Definitions for Existing ...
The step-by-step process to get to that definition is started by adding a property that does exist, and going to the definitions of...
Read more >
TypeScript: Type Definition Files
We need to add a definition file to help TypeScript to know about the existing properties, functions, arguments, and return values used in ......
Read more >
Parcel - How do I add type definitions?
The following would be a valid config, all .ts and .d.ts files in the ... are considered visible; specifically, that means packages within...
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