Comments (12)
+1
from typeforce.
Interesting, is this using uglifyjs
? If so, I'll see if I can replicate a test case ASAP 👍
from typeforce.
@dcousens were you able to replicate the issue?
from typeforce.
@mvayngrib sorry, I am not able to replicate this issue.
I've uglified the library using uglifyjs
and then tested importing it, with no issues.
Is there anything else I need to do?
from typeforce.
@dcousens sorry for the radio silence. Here's an example that breaks for me
// fnname.js
var typeforce = require('typeforce')
function Blah () {}
var blah = new Blah()
typeforce('Blah', blah)
browserify fnname.js | uglifyjs -c -m > fnname.min.js && node fnname.min.js
(function (exports, require, module, __filename, __dirname) { !function t(r,e,n){function i(u,a){if(!e[u]){if(!r[u]){var f="function"==typeof require&&require;if(!a&&f)return f(u,!0);if(o)return o(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var h=e[u]={exports:{}};r[u][0].call(h.exports,function(t){var e=r[u][1][t];return i(e?e:t)},h,h.exports,t,r,e,n)}return e[u].exports}for(var o="function"==typeof require&&require,u=0;u<n.length;u++)i(n[u]);return i}({1:[function(t,r,e){function n(){}var i=t("./"),o=new n;i("Blah",o)},{"./":2}],2:[function(t,r,e){(function(t){function e(t){if(void 0===t)return"";if(null===t)return"";var r=t.constructor.toString().match(/function (.*?)\(/);return r?r[1]:null}function n(r,n){r.split("|").forEach(function(i){switch(i){case"Array":if(null!==n&&void 0!==n&&n.constructor===Array)return;break;case"Boolean":if("boolean"==typeof n)return;break;case"Buffer":if(t.isBuffer(n))return;break;cas
TypeError: Expected Blah, got n [object Object]
at o (/Users/tenaciousmv/Code/typeforce/fnname.min.js:1:1468)
at /Users/tenaciousmv/Code/typeforce/fnname.min.js:1:1170
at Array.forEach (native)
at Object.n [as string] (/Users/tenaciousmv/Code/typeforce/fnname.min.js:1:775)
at r.exports (/Users/tenaciousmv/Code/typeforce/fnname.min.js:1:1703)
at Object.a.1../ (/Users/tenaciousmv/Code/typeforce/fnname.min.js:1:557)
at i (/Users/tenaciousmv/Code/typeforce/fnname.min.js:1:316)
at t (/Users/tenaciousmv/Code/typeforce/fnname.min.js:1:483)
at Object.<anonymous> (/Users/tenaciousmv/Code/typeforce/fnname.min.js:1:500)
at Module._compile (module.js:435:26)
from typeforce.
@mvayngrib right, that is simply a risk of uglify.
Due to it mangling the name Blah
.
This is an underlying issue with using quacksLike
, if you mangle the names, its inherently risky.
You're best bet is to exclude Blah
from being mangled in uglify-js using:
uglifyjs --reserved-names Blah
Alternatively, you can make your own type function (with all of its inherent risks):
function BlahType (value) { return value instanceof Blah }
typeforce(BlahType, blah)
or
typeforce(v => v instanceof Blah, blah)
I might make a typeforce.instanceOf(...)
type function so you can do typeforce(typeforce.instanceOf(Blah), blah)
to make this a bit simpler.
from typeforce.
Alternate alternatively: typeforce(Blah.name, blah)
might work.
(Blah.toString().match(/function (.*?)\s*\(/)[1]
if name
is undefined).
from typeforce.
right, that's more or less what i've been doing. It is what it is :)
from typeforce.
I'm going to close this as wontfix
, but it isnt' because I don't want to fix it, I just don't think we can due to the nature of it.
Maybe we should put a warning in the README?
from typeforce.
@dcousens yes to wontfix, yes to warning. Btw, i noticed this issue when I was uglifying bitcoinjs-lib, an older version, but i think the latest one uses quacksLike (which as you say has the same issue)
from typeforce.
@mvayngrib ah! You probably should have noticed the warning that is already in the bitcoinjs-lib README then 😄
from typeforce.
@dcousens haha, you got me, totally missed that
from typeforce.
Related Issues (20)
- Standard failing HOT 3
- maybe/oneOf JSON when used with complex types outputs [object Object]
- Change quacksLike to check expected properties, not name HOT 12
- Avoid recursive throwing / return Error HOT 5
- propertyKeyType for `typeforce.map` HOT 1
- typeforce 1.5.1 breaks bitcoinjs-lib 1.5.8 HOT 25
- Document quacksLike / tuple / map? HOT 4
- strict in quacksLike? HOT 2
- Add uglfiyjs mangling warning to README HOT 1
- isFiniteNumber? HOT 2
- split on multiple files HOT 2
- Tuple w/ strict should enforce maximum length HOT 1
- `.Object` and `.object` are too similar HOT 3
- Remove typeforce.object in favour of typeforce.compile
- Optional error information HOT 4
- Add exception capturing tests for arrayOf, map, object and tuple
- Error.captureStackTrace is undefined HOT 3
- anyOf should accept `Array` argument, not `arguments`
- Tests failing in Node <LTS
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeforce.