Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent "use strict" in typescript?

Tags:

typescript

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

VMundefined bundle.js:1722 SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.

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).

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");

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?

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);
like image 324
alexc Avatar asked Jul 08 '16 14:07

alexc


People also ask

What does use strict mean in TypeScript?

The "use strict" Directive It is not a statement, but a literal expression, ignored by earlier versions of JavaScript. The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables.

How do I turn off strict mode in angular 10?

Disable strict checks entirely by setting strictTemplates: false in the application's TypeScript configuration file, tsconfig. json. Disable certain type-checking operations individually, while maintaining strictness in other aspects, by setting a strictness flag to false.

How do I make TypeScript stricter?

You can either set the --strict flag on the command line or specify the strict option within your project's tsconfig. json file to opt into this mode. As of TypeScript 4.3 in August 2021, the --strict flag enables the following eight compiler options: --alwaysStrict.


1 Answers

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

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

like image 168
David Sherret Avatar answered Oct 21 '22 08:10

David Sherret