TypeScriptでstrictモードを有効化すると発生するエラー
Opened this issue · 0 comments
kappa0923 commented
@koba-ninkigumi san
概要
発生内容
TypeScriptでstrictモードで利用するとImplicit any等のエラーが発生するようです。
対応について
エラー改修する想定等ありますでしょうか?
もし予定が無いようであれば、私からPR送ってもよろしいでしょうか?
エラー詳細
エラーログ
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(1,5):
1:5 Variable 'CACHE' implicitly has type 'any[]' in some locations where its type cannot be determined.
> 1 | let CACHE = [];
| ^
2 | module YubinBango {
3 | export class Core {
4 | URL = 'https://yubinbango.github.io/yubinbango-data/data';
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(6,7):
6:7 Type 'null' is not assignable to type 'string'.
4 | URL = 'https://yubinbango.github.io/yubinbango-data/data';
5 | REGION: string[] = [
> 6 | null, '北海道', '青森県', '岩手県', '宮城県',
| ^
7 | '秋田県', '山形県', '福島県', '茨城県', '栃木県',
8 | '群馬県', '埼玉県', '千葉県', '東京都', '神奈川県',
9 | '新潟県', '富山県', '石川県', '福井県', '山梨県',
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(17,40):
17:40 Parameter 'callback' implicitly has an 'any' type.
15 | '宮崎県', '鹿児島県', '沖縄県'
16 | ];
> 17 | constructor(inputVal: string = '', callback?) {
| ^
18 | if(inputVal){
19 | // 全角の数字を半角に変換 ハイフンが入っていても数字のみの抽出
20 | const a:string = inputVal.replace(/[0-9]/g, (s: string) => String.fromCharCode(s.charCodeAt(0) - 65248));
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(21,15):
21:15 Type 'RegExpMatchArray | null' is not assignable to type 'RegExpMatchArray'.
Type 'null' is not assignable to type 'RegExpMatchArray'.
19 | // 全角の数字を半角に変換 ハイフンが入っていても数字のみの抽出
20 | const a:string = inputVal.replace(/[0-9]/g, (s: string) => String.fromCharCode(s.charCodeAt(0) - 65248));
> 21 | const b:RegExpMatchArray = a.match(/\d/g);
| ^
22 | const c:string = b.join('');
23 | const yubin7: string = this.chk7(c);
24 | // 7桁の数字の時のみ作動
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(23,15):
23:15 Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
21 | const b:RegExpMatchArray = a.match(/\d/g);
22 | const c:string = b.join('');
> 23 | const yubin7: string = this.chk7(c);
| ^
24 | // 7桁の数字の時のみ作動
25 | if (yubin7) {
26 | this.getAddr(yubin7, callback);
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(48,49):
48:49 Element implicitly has an 'any' type because index expression is not of type 'number'.
46 | selectAddr(addr: string[]):{[key:string]: string} {
47 | if (addr && addr[0] && addr[1]) {
> 48 | return this.addrDic(addr[0],this.REGION[addr[0]],addr[1],addr[2],addr[3])
| ^
49 | } else {
50 | return this.addrDic()
51 | }
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(53,24):
53:24 Parameter 'fn' implicitly has an 'any' type.
51 | }
52 | }
> 53 | jsonp(url: string, fn) {
| ^
54 | window['$yubin'] = (data) => fn(data);
55 | const scriptTag = document.createElement("script");
56 | scriptTag.setAttribute("type", "text/javascript");
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(54,14):
54:14 Element implicitly has an 'any' type because index expression is not of type 'number'.
52 | }
53 | jsonp(url: string, fn) {
> 54 | window['$yubin'] = (data) => fn(data);
| ^
55 | const scriptTag = document.createElement("script");
56 | scriptTag.setAttribute("type", "text/javascript");
57 | scriptTag.setAttribute("charset", "UTF-8");
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(54,27):
54:27 Parameter 'data' implicitly has an 'any' type.
52 | }
53 | jsonp(url: string, fn) {
> 54 | window['$yubin'] = (data) => fn(data);
| ^
55 | const scriptTag = document.createElement("script");
56 | scriptTag.setAttribute("type", "text/javascript");
57 | scriptTag.setAttribute("charset", "UTF-8");
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(61,29):
61:29 Parameter 'fn' implicitly has an 'any' type.
59 | document.head.appendChild(scriptTag);
60 | }
> 61 | getAddr(yubin7: string, fn):{[key:string]: string} {
| ^
62 | const yubin3 = yubin7.substr(0, 3);
63 | // 郵便番号上位3桁でキャッシュデータを確認
64 | if (yubin3 in CACHE && yubin7 in CACHE[yubin3]) {
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(61,33):
61:33 Function lacks ending return statement and return type does not include 'undefined'.
59 | document.head.appendChild(scriptTag);
60 | }
> 61 | getAddr(yubin7: string, fn):{[key:string]: string} {
| ^
62 | const yubin3 = yubin7.substr(0, 3);
63 | // 郵便番号上位3桁でキャッシュデータを確認
64 | if (yubin3 in CACHE && yubin7 in CACHE[yubin3]) {
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(64,21):
64:21 Variable 'CACHE' implicitly has an 'any[]' type.
62 | const yubin3 = yubin7.substr(0, 3);
63 | // 郵便番号上位3桁でキャッシュデータを確認
> 64 | if (yubin3 in CACHE && yubin7 in CACHE[yubin3]) {
| ^
65 | return fn(this.selectAddr(CACHE[yubin3][yubin7]));
66 | } else {
67 | this.jsonp(`${this.URL}/${yubin3}.js`, (data) => {
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(64,40):
64:40 Variable 'CACHE' implicitly has an 'any[]' type.
62 | const yubin3 = yubin7.substr(0, 3);
63 | // 郵便番号上位3桁でキャッシュデータを確認
> 64 | if (yubin3 in CACHE && yubin7 in CACHE[yubin3]) {
| ^
65 | return fn(this.selectAddr(CACHE[yubin3][yubin7]));
66 | } else {
67 | this.jsonp(`${this.URL}/${yubin3}.js`, (data) => {
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(64,46):
64:46 Element implicitly has an 'any' type because index expression is not of type 'number'.
62 | const yubin3 = yubin7.substr(0, 3);
63 | // 郵便番号上位3桁でキャッシュデータを確認
> 64 | if (yubin3 in CACHE && yubin7 in CACHE[yubin3]) {
| ^
65 | return fn(this.selectAddr(CACHE[yubin3][yubin7]));
66 | } else {
67 | this.jsonp(`${this.URL}/${yubin3}.js`, (data) => {
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(65,35):
65:35 Variable 'CACHE' implicitly has an 'any[]' type.
63 | // 郵便番号上位3桁でキャッシュデータを確認
64 | if (yubin3 in CACHE && yubin7 in CACHE[yubin3]) {
> 65 | return fn(this.selectAddr(CACHE[yubin3][yubin7]));
| ^
66 | } else {
67 | this.jsonp(`${this.URL}/${yubin3}.js`, (data) => {
68 | CACHE[yubin3] = data;
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(65,41):
65:41 Element implicitly has an 'any' type because index expression is not of type 'number'.
63 | // 郵便番号上位3桁でキャッシュデータを確認
64 | if (yubin3 in CACHE && yubin7 in CACHE[yubin3]) {
> 65 | return fn(this.selectAddr(CACHE[yubin3][yubin7]));
| ^
66 | } else {
67 | this.jsonp(`${this.URL}/${yubin3}.js`, (data) => {
68 | CACHE[yubin3] = data;
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(67,49):
67:49 Parameter 'data' implicitly has an 'any' type.
65 | return fn(this.selectAddr(CACHE[yubin3][yubin7]));
66 | } else {
> 67 | this.jsonp(`${this.URL}/${yubin3}.js`, (data) => {
| ^
68 | CACHE[yubin3] = data;
69 | return fn(this.selectAddr(data[yubin7]));
70 | });
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(68,11):
68:11 Variable 'CACHE' implicitly has an 'any[]' type.
66 | } else {
67 | this.jsonp(`${this.URL}/${yubin3}.js`, (data) => {
> 68 | CACHE[yubin3] = data;
| ^
69 | return fn(this.selectAddr(data[yubin7]));
70 | });
71 | }
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(68,17):
68:17 Element implicitly has an 'any' type because index expression is not of type 'number'.
66 | } else {
67 | this.jsonp(`${this.URL}/${yubin3}.js`, (data) => {
> 68 | CACHE[yubin3] = data;
| ^
69 | return fn(this.selectAddr(data[yubin7]));
70 | });
71 | }
ERROR in /path/to/node_modules/yubinbango-core2/yubinbango-core.ts(76,1):
76:1 Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
74 | }
75 |
> 76 | export = YubinBango;
| ^
77 |