1

Altho I have strict: true in my tsconfig.json, this doesn't error:

const a: (b?: string) => string[] =
         (c : string) => c.split(',');
           ^
  should scream in vein

How do I get TypeScript to panic about this?

Packages versions:

  • typescript 2.5.3
  • ts-loader 3.1.1
  • webpack 3.6.0

Here's my complete tsconfig.json:

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs",
    "strict": true,
    "noImplicitAny": true,
    "allowJs": true,
    "sourceMap": true,
    "allowSyntheticDefaultImports": false,
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "preserveConstEnums": false,
    "removeComments": false,
    "lib": [
      "es5",
      "es6",
      "dom",
      "es2015.core",
      "es2015.collection",
      "es2015.generator",
      "es2015.iterable",
      "es2015.promise",
      "es2015.proxy",
      "es2015.reflect",
      "es2015.symbol",
      "es2015.symbol.wellknown",
      "esnext.asynciterable"
    ]
  },
  "exclude": [
    "node_modules",
    "test",
    ".git"
  ]
}
0

1 Answer 1

1

Something funky is going on in your set up. I am use TypeScript 2.6.1 with your tsconfig.json and the code:

const a: (b?: string) => any = (b: string) => 1;

Because you have the strict flag on, that includes the two flags you need to get an error; strictNullChecks and strictFunctionTypes. When I run:

tsc

I receive the message:

app.ts(1,7): error TS2322: Type '(b: string) => number' is not assignable to type '(b?: string | undefined) => any'.   Types of parameters 'b' and 'b' are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.

How are you running the compiler? The reason I ask is that it will only use your config file if you "run it plain" as shown above. If you pass a file name argument, for example, you'll not use your config:

tsc app.ts

Results in no errors, because you aren't using your tsconfig.json any more.

Sign up to request clarification or add additional context in comments.

1 Comment

it seems that my TS version was bad. TS panics just fine with 2.6.1 :}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.