emeryao / typed-jweixin

TypeScript declaration file for Wexin JSSDK jweixin.d.ts
MIT License
15 stars 12 forks source link

your sample code cause a compile error #6

Closed genru closed 6 years ago

genru commented 6 years ago

I follow your sample code in README, without imprt any file and do same thing as you sampled, when I ng build, an error displayed

ERROR in src/app/rank/rank.component.ts(42,9): error TS2304: Cannot find name 'wx'.
        wx.config(res);
        wx.ready(() => {
          wx.onMenuShareAppMessage({
            link: this.document.location.href,
            title: kTitle[this.type],
            desc: '主播,标签,机构,类目,流量,首页入围等排名',
            imgUrl: 'http://weixin.udaren.com/assets/images/logo.png'
          });
        })

it seems wx does not declared, could you update your document to show how to make it work?

emeryao commented 6 years ago

ok I'll check it up

emeryao commented 6 years ago

Have you include jweixin.d.ts to your project folder ?

genru commented 6 years ago

'include'? I guess no, I do not understand how to do it? I just yarn install and use it in ts file.

emeryao commented 6 years ago

this repo does not support yarn for now please follow the install documentation

genru commented 6 years ago

thank you for your instruction. unfortunately it does not work, error remains. I believe yarn is compatible with npm, it maybe is not the cause.

belowing are what I followed 1) install jweixin

npm install typed-jweixin --save-dev

2) try to build prject

ng build

I use angular 6, is this a angular 6 compatibility issue?

emeryao commented 6 years ago

I'm sorry but yarn is not compatible with npm in this case cause the version in package.json is 1.0.0-update.1 which yarn does not support while npm does

emeryao commented 6 years ago

and there should not be any compatibility issues with @angular@6

emeryao commented 6 years ago

so just make sure you've include the jweixin.d.ts in your project if so please let me know and I'll do some further investigation

emeryao commented 6 years ago

could you pop up some error message that may helps ?

genru commented 6 years ago

error message shows

ERROR in src/app/rank/rank.component.ts(42,9): error TS2304: Cannot find name 'wx'.

index.d.ts already exists in node_modules/@types/jweixin.

does not find jweixin.d.ts in project folder. hope this helpful.

emeryao commented 6 years ago

index.d.ts already exists in node_modules/@types/jweixin. does not find jweixin.d.ts in project folder. hope this helpful.

this is expected that how the declaration file is being included if the node_modules/@types/jweixin/index.d.ts have the same content with jweixin.d.ts

I'll do some investigation.

PS it's appreciated if you pop up some pieces of your code that errors

genru commented 6 years ago

I have an component to show rank data. and I need to config wechat jssdk first.

import { Component, OnInit, Inject } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { HttpClient, HttpParams } from '@angular/common/http';
import { environment } from '../../environments/environment';
import { Title, DOCUMENT } from '@angular/platform-browser';

@Component({
  selector: 'app-rank',
  templateUrl: './rank.component.html',
  styleUrls: ['./rank.component.css']
})
export class RankComponent implements OnInit {

  type: number;
  cate: number;
  shopTopPillows = false;
  dataSource = [];
  showQR = false;
  constructor(private route: ActivatedRoute, private http: HttpClient, private titleService: Title
    , @Inject(DOCUMENT) private document: any) { }

  ngOnInit() {
    this.http.get('/wechat/config').subscribe((data: any) => {
      wx.config(data);      // <--- fail here
    });
  }

}

this is what i do.

emeryao commented 6 years ago

hi @genru I got the tricky 🎉

projects created with ng new have a ./src/tsconfig.app.json with default content

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "outDir": "../out-tsc/app",
        "types": []
    },
    "exclude": []
}

just remove the line "types":[] solves this issue 🤣

genru commented 6 years ago

thanks for your workaround for this, if some update made to resolve this issue would be great, or consider to update README.

thanks

emeryao commented 6 years ago

REAEME.me already updated 😆

emeryao commented 6 years ago

@genru as you can see here aws said the same 😝