Justin Young Justin Young - 1 year ago 303
TypeScript Question

How to fix `Argument of type number is not assignable to string`?

New to angular 2 & typescript. Trying to test some pipes. I keep getting this error in my tests:

ERROR in [default]
Argument of type 'number' is not assignable to parameter of type

Any idea of what I'm doing wrong?


import { .... }

@Pipe({name: 'inflection'})
export class InflectionPipe implements PipeTransform {
transform(value: string, args: string[]): any {
return inflection.inflect(value, args)


import {....}

describe('InflectionPipe', () => {
// provide our implementations or mocks to the dependency injector
beforeEach(() => TestBed.configureTestingModule({
providers: [

it('should inflect different values', inject([InflectionPipe], (inflectionPipe: InflectionPipe) => {

expect(inflectionPipe.transform('goose', 2)).toEqual('geese');



Answer Source

Look at your transform signature

transform(value: string, args: string[])

and look how you are trying to call it

inflectionPipe.transform('goose', 2)

It expects a string[] but you are passing a number. Not sure what you are trying to do, but you should fix it accordingly. Maybe transform('goose', ['2'])

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download