Consider adding a TypeScript definitions file
See original GitHub issueI’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:
- Created 8 years ago
- Reactions:7
- Comments:24
Top 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 >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 FreeTop 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
Top GitHub Comments
I recently created a package that provides TypeScript definitions for the JSON representation of WordPress core PHP objects (
WP_Error
,WP_Post
, andWP_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!I came across this: https://www.npmjs.com/package/@types/wpapi