Skip to content

Instantly share code, notes, and snippets.

View SamPruden's full-sized avatar

Sam SamPruden

View GitHub Profile
@SamPruden
SamPruden / interface augmentation typing fun.ts
Last active August 7, 2017 19:38
Messing around with a trick that allows basic type switching in TypeScript, and provides the ability to make DeepReadonly<T>
// WHAT IS THIS?
// This is me playing around with a cool (but dirty) trick
// Some interfaces can be globally augmented to provide info to the type system
// This then allows some basic type switch and retrieval operations
// I needed a DeepReadonly<T> for a thing, I think I have it now
// Built/tested in 2.5.0-dev20170803
// FUTURE PLANS
// - This needs lots of tidying and renaming
// - Do more stuff
@SamPruden
SamPruden / typescript filtering notes.md
Last active August 8, 2017 05:56
Personal notes on type filtering in TS, not quite issue worthy yet

This is now an issue at #17678, if you're here you should probably be there.

I'll probably put this up as a TS issue at some point, but I've been spamming them a bit over the last few days and I'm trying to play it cool.

This arrogantly assumes the implementation of #17636.

Aim of mapped-type filtering

Given some type Foo, construct a new type Bar with a subset of the members of Foo, where that subset is determined by a type predicate. Both the key and type of the member should be available to the predicate. Type predicates should have the full power of the type system.

This is analgous to Array.prototype.filter, where the index and item value are available to the predicate.