Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with source-map-loader when using webpack: "The keyword 'interface' is reserved" #63

Closed
sledorze opened this issue Jul 24, 2017 · 8 comments

Comments

@sledorze
Copy link
Collaborator

(Issue using io-ts 0.5.0, 0.5.1 and 0.6.0)
The problem is that Webpack transform userland code of io-ts like this:

import { _A, array, boolean, failure, interface, intersection, number, partial, recursion, string, success } from 'io-ts/index';

importing directly 'interface' even if the original code was using it like so:

import * as t from 'io-ts';

const myType = t.interface({
...
})

Resulting in an error when source-map-loader kicks in:

The keyword 'interface' is reserved (1:38) You may need an appropriate loader to handle this file type.

Also this generates a visual error in visual code studio.

A solution would be to provide an alternative keyword.

@sledorze
Copy link
Collaborator Author

Actually using
t._interface
is ALREADY available, so that's all I needed.

@sledorze sledorze reopened this Jul 24, 2017
@sledorze
Copy link
Collaborator Author

sledorze commented Jul 24, 2017

I am reopening this issue because, the same problem happens with
t.null

@sledorze
Copy link
Collaborator Author

@gcanti the problem is pretty general in this setting.
Maybe we can double all the exported definitions whose names match reserved keywords?

@gcanti
Copy link
Owner

gcanti commented Jul 25, 2017

@sledorze Could you please put up a repo reproducing the error?

Based on your description though, it doesn't seem an issue with io-ts, it rather seems a bug in the transformer

@gcanti
Copy link
Owner

gcanti commented Jul 25, 2017

@sledorze anyway I'm ok with exporting some alias, I propose

  • type as an alias of interface
  • nullType as an alias of null

does undefined raise an error too? (EDIT it shouldn't)

@sledorze
Copy link
Collaborator Author

sledorze commented Jul 25, 2017

@gcanti undefined is 'correctly webpacked' to something like: undefined as undefined$1
I think it could help a lot of people.
nullType is ok
type may also be a reserved keyword, the existing _interface is fine to me but if we aim at homogeneity, why not interfaceType ?

@gcanti
Copy link
Owner

gcanti commented Jul 25, 2017

type is not a reserved keyword. Also seems appropriate

type Person = {
  name: string
}

const Person = t.type({
  name: t.string
})

@sledorze
Copy link
Collaborator Author

It is a typescript keyword, not a js one, you're right
Hoping it will not pose an issue with tooling then :)

gcanti added a commit that referenced this issue Jul 25, 2017
@gcanti gcanti closed this as completed in e5c0998 Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants