-
Notifications
You must be signed in to change notification settings - Fork 191
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
Consider adding a TypeScript definitions file #149
Comments
@MurhafSousli I am not very familiar with TypeScript but I'll test this out and see if I can figure what's up |
Thank you |
I'm not sure what's up with this, @MurhafSousli -- could you put together a gist demonstrating the environment in which this issue occurs? Thanks! |
Well in order to use any external library in a typescript application, we need a typescript definition file for the library
|
@MurhafSousli TypeScript support is not a current roadmap priority vs missing features, but if you're able to put together a definition file I'd be happy to merge it in as a PR. I'm re-naming this issue to track potentially adding a typescript file later on. |
@MurhafSousli One wrinkle in providing a typescript file is that the functions available to the API client now depend on the discovery or bootstrapping process; given the customizability of a WordPress install it is actually not possible for us to authoritatively specify all available methods up-front, since a site might not even provide ^ I recognize the irony of closing something after a month when it took me months to respond initially; so please feel free to re-open if you wish to discuss further. |
@kadamwhite Hi, I'm sorry I didn't respond I just read it now, I don't really know how to make definition file for a javascript library, so I had write my own service file in typescript. |
I am about to use in angular 2 app .. |
Have anyone found a workaround to be able to use this lib in their typescript project? |
@malfborger If you are working in angular project, try this https://github.com/MurhafSousli/ngx-wordpress |
thx guys @klihelp @MurhafSousli ! But no way to use this repo? |
I may use this as well. For start, just require the file, as example: |
These can be used to put a base for all types, then extend and maintain the types. ⇒ dts-gen -m wpapi -d wpapi
⇒ ls types/wpapi
index.d.ts tsconfig.json tslint.json wpapi-tests.ts |
I ran into this error: Could not find a declaration file for module 'wpapi'. 'C:/Users/jpoll/josh-dev/use-wordpres/node_modules/wpapi/wpapi.js' implicitly has an 'any' type.
Try `npm install @types/wpapi` if it exists or add a new declaration (.d.ts) file containing `declare module 'wpapi';` I got this far into a import WPAPI from 'wpapi';
import { useRef } from 'react';
export default function useWordPres(endpoint: string) {
let wp = useRef(new WPAPI({ endpoint }));
return {
wp: wp.current,
};
} |
@kadamwhite I'm going to start a PR based on what @iamandrewluca suggested as I think I have it right locally. Can you reopen this issue please? Would be cool to work on typescript support at WCUS contributor day if you're able to. |
@MurhafSousli A solution for packages that does not have definitions is. declare module 'wpapi' Add this file to {
"compilerOptions": {
"types": [
"./src/my-definitions.d.ts"
],
}
} |
@Shelob9 i'm in, ping me if have any questions. |
@iamandrewluca Awesome. I opened #447 for this. I'd be happy to work on typescript for this, but I'm not hyper educated on this, just getting into typescript recently, so if you can help get #447 done, that would be HUGE help. Didn't get a chance to finish this conversation with @kadamwhite I saw him last time. I'm getting ahead of bugging him about Typescript support during WordCamp US :) |
Notes on my conversation with @kadamwhite at WordCamp US. We talked about three general solutions to address lack of typescript support:
We agreed that option one makes sense, and maybe option 2 is woth exploring in the future. @kadamwhite does not see option 3 as inline with the goals of this project. I think he's right. But I do think |
I recently created a package that provides TypeScript definitions for the JSON representation of WordPress core PHP objects ( |
@johnbillion I have most of the default route response objects described as Typescript interfaces in a side project. I can extract them into a PR to your package tomorrow if you want. |
Great! |
I came across this: https://www.npmjs.com/package/@types/wpapi |
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 errorcan't find module
I also tried
require( 'wordpress-rest-api/wp' )
gave the errorUnhandled rejection Error: Error on fetch for node.extend.js
Thanks.
The text was updated successfully, but these errors were encountered: