Skip to content

Instantly share code, notes, and snippets.

View bluepnume's full-sized avatar

Daniel Brain bluepnume

  • OneText
  • San Jose
View GitHub Profile
@bluepnume
bluepnume / typescripts-number-type-is-a-lie
Last active May 27, 2026 01:38
TypeScript needs units
# TypeScript's number type is a lie
`5000` is `5000` is `5000`.
It might be milliseconds. It might be seconds. It might be the year, the price in cents, the height in pixels, or the number of bytes in your payload. TypeScript has no idea. It will happily let you pass any of them to any function that takes a `number`. That is not type safety. That is a vibe.
This is the bug you wrote last week:
```ts
setTimeout(retry, 5); // 5 milliseconds, not 5 seconds. Whoops.
((message) => console.log(`"${ message.replace(/[\u007F-\uFFFF]/g, chr =>
'\\u' + ('0000' + chr.charCodeAt(0).toString(16)).substr(-4)
) }"`))('hello! 😀');
const randomPercentile = () => {
return Math.floor(Math.random() * 100);
};
const events = [
{
name: 'A',
percentage: 33
},

We're OneText

Good to meet you! We just started OneText

  • Jonathan Fudem is steering the ship
  • Daniel Brain is cranking out code

We're Ex-PayPal

During our combined 12 years at PayPal Checkout, we launched and scaled some of the world's most popular buying experiences.

const useElementWithSize = () => {
const [ currentElement, setCurrentElement ] = useState(null);
const [ width, setWidth ] = useState(null);
const [ height, setHeight ] = useState(null);
const updateDimensions = (element) => {
setWidth(element?.offsetWidth);
setHeight(element?.offsetHeight);
};
const mine = async () : Promise<void> => {
await loop(async () => {
const transactions = mempool.slice(0, BLOCK_SIZE_LIMIT);
const hashedBlock = await blockchain.createBlock(await keypair.publicKey, transactions);
if (hashedBlock) {
await network.broadcast('ADD_BLOCK', hashedBlock);
}
});
};
network.listen('ADD_BLOCK', async (hashedBlock) => {
mempool = [];
await blockchain.addBlock(hashedBlock);
});
const send = async (receiver : string, amount : number, fee : number) : Promise<void> => {
const signedTransaction = await signAndPack({
sender: await keypair.publicKey,
receiver,
amount,
fee
}, await keypair.publicKey, await keypair.privateKey)
await network.broadcast('ADD_TRANSACTION', signedTransaction);
};
network.listen('ADD_TRANSACTION', async (signedTransaction) => {
mempool.push(signedTransaction);
});
const keypair = KeyPair();
const network = Network();
const blockchain = BlockChain();
let mempool = [];