防止“严格使用"在打字稿中? [英] Prevent "use strict" in typescript?

查看:29
本文介绍了防止“严格使用"在打字稿中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 iOS 设备上加载我的应用时,出现以下错误;

When trying to load my app on an iOS device I get the following error;

VMundefined bundle.js:1722 语法错误:意外的关键字const".严格模式不支持 const 声明.

这个错误发生在 iPhone 5s/6s + 我试过的几个不同的 iPad 上(不记得是哪个).它也不适用于HTC.在我尝试过的任何三星/Windows 手机上都没有发生此错误.它也适用于台式机.(我还没有尝试在 Mac 上运行它).

This error occurred on iPhone 5s/6s + a couple of different iPad's I tried (can't remember which). It also did not work on the HTC one. This error did not occur on any samsung/windows phones I tried. It also worked on desktops. (I have not tried to run it on a mac yet).

这是来自 bundle.js 的那行代码;

Here is that line of code from the bundle.js;

{}],12:[function(require,module,exports){
"use strict";
const guage_1 = require("./charts/kpi/guage");
const stacked_1 = require("./charts/area/stacked");
const barChart_1 = require("./charts/compare/barChart");

当我从 bundle.js 中删除use strict"时,它在所有设备上都能正常工作.只是想知道是否有办法确保打字稿不会使用严格使用"进行编译或修复 iOS 设备的问题?

When I remove the "use strict" from the bundle.js it works fine on all devices. Just wondering if there is a way to make sure typescript does not compile with "use strict" or a fix for the problem with iOS devices?

这是我用于编译的 gulpfile(按照在 typescripts 网站上发布的指南进行操作))

Here is my gulpfile for compiling (followed the guide published on typescripts website)

var gulp = require('gulp'),
    sourcemaps = require('gulp-sourcemaps'),
    source = require('vinyl-source-stream'),
    tsify = require('tsify'),
    browserSync = require('browser-sync'),
    postcss = require('gulp-postcss'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    rename = require('gulp-rename'),
    watchify = require("watchify"),
    browserify = require('browserify'),
    gutil = require("gulp-util"),
    buffer = require('vinyl-buffer'),
    processorArray = [
       ...
    ],
    watchedBrowserify = watchify(browserify({
        basedir: '.',
        debug: true,
        entries: ['src/main.ts'],
        cache: {},
        packageCache: {}
    }).plugin(tsify)),
    devPlugin = './src/plugins/';

function bundle() {
    return watchedBrowserify
        .bundle()
        .pipe(source('bundle.js'))
        .pipe(gulp.dest("dist"));
}

gulp.task('default', ['styles',  'browser-sync', 'watch'], bundle, function() {

    return browserify({
            basedir: '.',
            debug: true,
            entries: ['src/main.ts'],
            cache: {},
            packageCache: {}
        })
        .plugin(tsify)
        .transform("babelify")
        .bundle()
        .pipe(source('bundle.js'))
        .pipe(buffer())
        .pipe(sourcemaps.init({
            loadMaps: true
        }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('dist'))


});

watchedBrowserify.on("update", bundle);
watchedBrowserify.on("log", gutil.log);

推荐答案

您可以通过使用 --noImplicitUseStrict 编译器选项—在中将"noImplicitUseStrict": true添加到"compilerOptions"href="https://www.typescriptlang.org/docs/handbook/tsconfig-json.html" rel="noreferrer">tsconfig.json.

You can do that by compiling with the --noImplicitUseStrict compiler option—add "noImplicitUseStrict": true to "compilerOptions" in tsconfig.json.

这样做会阻止编译器发出"use strict".

Doing so will prevent the compiler from emitting "use strict".

这篇关于防止“严格使用"在打字稿中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆