Skip to content

Conversation

@ckknight
Copy link

@ckknight ckknight commented Oct 8, 2015

This comes out of my desire to just import an empty string, but decided to fill out the other primitive types as well (except for Symbol).

Since primitive in JS are immutable, the Object.freeze that takes place in other modules does not need to occur.

@iclanzan
Copy link
Owner

iclanzan commented Oct 8, 2015

What’s the use case for these though?

@ckknight
Copy link
Author

ckknight commented Mar 8, 2016

The use case is when aliasing something that would have or could have returned that type instead of an object

@iclanzan
Copy link
Owner

iclanzan commented Mar 8, 2016

I am sorry but I still can’t quite get it. Can you provide some code as an example?

@ckknight
Copy link
Author

Say you have a library which does some calculations and returns a string.

You could use webpack or another build step to re-alias that library to easily point to the empty string.

@MoOx MoOx mentioned this pull request May 18, 2016
@MoOx
Copy link

MoOx commented May 18, 2016

When using Flow and the module.name_mapper option, this can totally make sense. +1 for this

exports.functionThatReturnsNull = require('./functionThatReturnsNull');
exports.functionThatReturnsThis = require('./functionThatReturnsThis');
exports.functionThatReturnsArgument = require('./functionThatReturnsArgument');
exports['boolean'] = require('./boolean');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use bracket notation for these?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean is probably a reserved word.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but reserved words can still be used as key in ES5 and up.
Also, importing/requiring these will cause a bit of a nuisance since you can’t do import {null} from 'empty'.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import {null as nullValue} from 'empty'

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

Successfully merging this pull request may close these issues.

3 participants