Add "???" Unimplemented
Can you give a simple example?
I think it can be easily implemented with decorators (
tc39/proposal-decorators).
Something like @unimplemented
.
In my opinion it doesn't offer enough benefits to be added as a new syntax.
Em qua, 21 de mar de 2018 às 04:02, Naveen Chawla <naveen.chwl at gmail.com>
escreveu:
Simple example (ts):
interface SearchFunc {
(source: string, subString: string): boolean;
}
// Later
let mySearch: SearchFunc;
mySearch = function(source: string, subString: string) { ??? }
Simple example (js):
class MyClass = {
foo() { return "foo"; }
bar() { return "bar"; }
}
class ExtendClass extends MyClass {
foo(){ ??? }
bar(){ return `extended bar`; }
}
// Elsewhere
myRunner = (classInstance) => `${classInstance.foo()} ::
${classInstance.bar()}`;
myRunner(myClassInstance);
myRunner(extendedClassInstance);
Decorations would be good for classes, but don't work for regular methods.
I'm not sold we need new syntax for this -- I just find myself reaching for
the ???
symbol. Especially in a typed language or in any instance that we
have a class and extended paradigm, or when you have a prescribed "object"
shape.
I would suggest, if you have support in your editor, just making a
???
snippet expand to throw new Error("unimplemented")
. I've been
doing similar (mod the snippet) for a while, and it's worked pretty
well.
Isiah Meadows me at isiahmeadows.com
Looking for web consulting? Or a new website? Send me an email and we can get started. www.isiahmeadows.com
Not a bad idea -- I agree that it really belongs here, but its value is much higher in something like TypeScript, where you can keep the typing signature but have a missing implementation.
Even in TypeScript, never
(the type of functions that never return -
throwing ≠ returning) is the subtype of all types, even primitives.
Isiah Meadows me at isiahmeadows.com
Looking for web consulting? Or a new website? Send me an email and we can get started. www.isiahmeadows.com
const ɁɁɁ = () => { throw new Error('Method not defined'); };
Thomas Grainger
With the advent of TypeScript, classes, etc one feature I liked from scala is:
???
, the Predef.??? token.Basically, you can place
???
which would type as whatever the method is typed as (for things like Typescript, Symbol definitions, etc.), and when run, throws the "NotImplementedError".This is useful when writing libraries or other code -- more readable that "cannot call undefined" when the method is missing, and a nice placeholder for young APIs.
This is basically the same as writing:
throw new Error('Unimplemented')
.