add boolean, null, number, string, and undefined#1
add boolean, null, number, string, and undefined#1ckknight wants to merge 1 commit intoiclanzan:masterfrom ckknight:master
Conversation
|
What’s the use case for these though? |
|
The use case is when aliasing something that would have or could have returned that type instead of an object |
|
I am sorry but I still can’t quite get it. Can you provide some code as an example? |
|
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. |
|
When using Flow and the |
| exports.functionThatReturnsNull = require('./functionThatReturnsNull'); | ||
| exports.functionThatReturnsThis = require('./functionThatReturnsThis'); | ||
| exports.functionThatReturnsArgument = require('./functionThatReturnsArgument'); | ||
| exports['boolean'] = require('./boolean'); |
There was a problem hiding this comment.
Why did you use bracket notation for these?
There was a problem hiding this comment.
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'.
There was a problem hiding this comment.
import {null as nullValue} from 'empty'
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.freezethat takes place in other modules does not need to occur.